Make array of all GET-variables
I'm trying to make an array from all the GET-variables passed to a PHP script. So far I haven't found any way to do this.
Is this possible?
Solution 1:
It's already there by default:
print_r($_GET); // for all GET variables
print_r($_POST); // for all POST variables
PHP docs on all available superglobals
Solution 2:
There is a $_GET
super global array to get all variables from query string.
// print all contents of $_GET array
print_r($_GET);
// print specific variable
echo $_GET['key_here'];
You can also use foreach
loop to go through all of them like this:
foreach($_GET as $key => $value)
{
echo 'Key = ' . $key . '<br />';
echo 'Value= ' . $value;
}
Solution 3:
GET variables are allready passed as an array
Solution 4:
The $_REQUEST variable is:
An associative array that by default contains the contents of $_GET, $_POST and $_COOKIE.
http://www.php.net/manual/en/reserved.variables.request.php
That could help