i am retrieving the parameters using $_REQUEST. Is there a way of finding total no. of parameters in URL instead of retrieving each one and then counting ?
4 Answers
This will give you the total number of & separated URL query parameters:
count(explode('&', $_SERVER['QUERY_STRING']))
If you only want unique parameters, use $_GET instead:
count($_GET)
2 Comments
Retrieve them with $_GET. This should be enough.
Example:
// url: index.php?a=1&b=2&c=3
echo count($_GET); // 3 params, $_GET['a'], $_GET['b'], $_GET['c']
Note: you can also pass arrays in url ( check here ), and the whole array is counted once.
1 Comment
If you only want the parameters in the URL, it's better to use $_GET. Since $_REQEUST contains the contents of $_GET, $_POST and $_COOKIE. see php.net
And if you want to know the number of parameters, you can get count the number of parameters that are in the URL using this: count($_GET).