By using the brackets []
you explicitly tell PHP to create an array, just don't use the brackets:
<input type="text" name="foo_0" value="x" />
<input type="text" name="foo_1" value="y" />
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.
$post = array();
foreach ($_POST as $key => $value) {
if (!is_array($value)) {
$post[$key] = $value;
} else {
foreach ($value as $foo => $item) {
$post[$foo] = $item;
}
}
}
Or read some great input on array flattening.