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,477
  • 9
  • 34
  • 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
  • 29,893
  • 8
  • 74
  • 71
Ibu
  • 41,298
  • 13
  • 73
  • 100
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
  • 44,769
  • 7
  • 56
  • 100
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
  • 92,047
  • 28
  • 163
  • 215