iMohammadreza iMohammadreza - 1 year ago 99
PHP Question

How to set optional get in php

In a php file named show.php I used GET method to receive datas.

In newer version of my app, I have another GET method for offset. And that's an optional data.

How can I optimise php file for working with and without get methods. In another meaning, How to set optional GET method?

Answer Source

Use a default value and a ternary condition?:

$limit = isset($_GET['limit']) ? $_GET['limit'] : 1;
$offset = isset($_GET['offset']) ? $_GET['offset'] : 1;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download