PHP will automatically convert
<input type="text" name="foo[0]" value="x" />
<input type="text" name="foo[1]" value="y" />
into
$_POST['foo'] = array(
0 => 'x',
1 => 'y'
);
Which is what you want most of the time. However, in this case I would like this not to happen. Is there anyway to tell PHP to not do this?
I realize I could parse php://input myself, but I’d rather not do that if I can avoid it.
I also don’t have the option of renaming the input names.
By using the brackets
[]you explicitly tell PHP to create an array, just don’t use the brackets:The fields will be available in the $_POST array as
$_POST['foo_0']and$_POST['foo_1'].If you don’t have influence on the markup (which is weird, since you could always change them client side) you need to flatten the array.
Or read some great input on array flattening.