Reputation: 16792
Say your HTTP request is formatted like this:
GET /path/to/file.php?var[]=1&var[]=2
PHP will populate that into an array named $_GET
: array('var' => array(1, 2))
My question is... is this a PHP thing or is this behavior governed by an RFC? How would a web accessible node.js or Python script deal with this?
Upvotes: 2
Views: 44
Reputation: 360662
PHP by default will overwrite previous values, and you end up with the LAST key:value pair found in the query string. But in PHP you can use the []
array as fieldname hack:
example.com?foo=bar&foo=baz&foo=qux
example.com?foo[]=bar&foo[]=baz&foo[]=qux
Line #1 produces $_GET like this:
$_GET = array(
'foo' => 'qux'
);
Line #2 produces
$_GET['array'] = array
'foo' => array('bar', 'baz', 'qux');
}
Note that this behavior is PHP specific. Other languages do their own thing. As far as I remember, Perl by default will keep all values as an array.
Upvotes: 2
Reputation: 1689
This is a specific feature of PHP with no related RFCs or other specs. I can't find any specific statements to that effect, but reading this FAQ Q/A seems to imply the same:
http://docs.php.net/manual/en/faq.html.php#faq.html.arrays
Upvotes: 1