How I PHP: Using defaults for input arguments
by Arnold Daniels on 06/30/2008Just a short one today, because I’m really busy (un)fortunately.
You can take out and check each argument at a time:
1 2 3 4 | $search = isset($_GET['search']) ? $_GET['search'] : null; $page = isset($_GET['page']) ? $_GET['page'] : 1; $limit = isset($_GET['limit']) ? $_GET['limit'] : 15; // etc |
$search = isset($_GET['search']) ? $_GET['search'] : null; $page = isset($_GET['page']) ? $_GET['page'] : 1; $limit = isset($_GET['limit']) ? $_GET['limit'] : 15; // etc
But to do it in one go, just do:
1 | $args = $_GET + array('search'=>null, 'page'=>1, 'limit'=>15); |
$args = $_GET + array('search'=>null, 'page'=>1, 'limit'=>15);Note that in some cases it is important to filter your input, that is not done here.





There are 9 comments in this article: