1

Possible Duplicate:
PHP: form input field names containing square brackets like field[index]

I just saw a URL parameter with brackets in it, does anyone know what could be the reason for using brackets?

www.website.com?request[product]=Digital+Printing

Thanks

Community
  • 1
  • 1
nasty
  • 6,797
  • 9
  • 37
  • 52

3 Answers3

4

you can pass parameters in the format to make arrays

<input type="text" name="request[product]" value="..."/>
<input type="text" name="request[item]" value="..."/>

www.website.com?request[product]=Digital+Printing&request[item]=something

so in the back end you can access it like so:

echo $_GET['request']['product']; // Digital Printing
echo $_GET['request']['item']; // something
sachleen
  • 30,730
  • 8
  • 78
  • 73
Ibu
  • 42,752
  • 13
  • 76
  • 103
4

Its for passing arrays.

//Example: ?request[product]=Digital+Printing&request[key]=abc123
var_dump($_GET['request']);
/**
 * array (size=2)
      'product' => string 'Digital Printing' (length=16)
      'key' => string 'abc123' (length=6)
 */

Its used more in POST for sending multiple values with the same key name, like a multi select option or checkboxes.

Lawrence Cherone
  • 46,049
  • 7
  • 62
  • 106
3

$_GET['request'] is an array so it is represented has request[product]

if you run

  var_dump($_GET);

You would get

array
  'request' => 
    array
      'product' => string 'Digital Printing' (length=16)
Baba
  • 94,024
  • 28
  • 166
  • 217