tags:

views:

114

answers:

4

Hey.

I'm trying to get an array of all GET-variables passed to a PHP document.

Is this possible?

Thanks. :)

+12  A: 

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

Pekka
Hahahah, seriously, I am so stupid. Thanks :)
Emil
How would you use a foreach-loop to print key and value of an array (like `$_GET`)?
Emil
@Emil `foreach ($_GET as $key => $value) echo "Key: $key Val: $value<br>";`
Pekka
Thanks :) Is it really that easy? I guess I'm a n00b after all :p
Emil
+3  A: 

GET variables are allready passed as an array

Kaaviar
+3  A: 

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;
}
Sarfraz
How would you use a foreach-loop to print both key and value of $_GET?
Emil
@Emil: See my updated answer for foreach loop.
Sarfraz
Thanks. :):):):)
Emil
@Emil: You are welcome ...
Sarfraz
(the ":)"-s was to fulfill StackOverflow's stupid character minimum.)
Emil
A: 

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

karlw