Make array of all GET-variables
83,445
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
extract($_REQUEST);
Will get every variable passed by post or get and make into a new variable
Solution 5
Get all GET params by :
$all_params = $_SERVER['QUERY_STRING']
Related videos on Youtube
Comments
-
Emil over 4 years
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?
-
Emil almost 14 yearsHow would you use a foreach-loop to print key and value of an array (like
$_GET
)? -
Pekka almost 14 years@Emil
foreach ($_GET as $key => $value) echo "Key: $key Val: $value<br>";