48

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
  • 7,220
  • 17
  • 76
  • 135

6 Answers6

100

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
  • 442,112
  • 142
  • 972
  • 1,088
19

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
  • 377,238
  • 77
  • 533
  • 578
7

GET variables are allready passed as an array

Boris Delormas
  • 2,509
  • 1
  • 19
  • 27
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

karlw
  • 668
  • 4
  • 13
4

Get all GET params by :

$all_params = $_SERVER['QUERY_STRING']

Pradeep Kumar Kushwaha
  • 2,231
  • 3
  • 23
  • 34
4
extract($_REQUEST);

Will get every variable passed by post or get and make into a new variable