Question

If the request contains a field named x[y], PHP's resultant $_POST array looks like the following:

array (
    'x' => array (
        'y' => ''
    )
)

Is there anyway I can stop this multidimensional array parsing and just have an array:

array (
    'x[y]' => ''
)

?

Thanks.

Was it helpful?

Solution

No because it's the browser that sends values as a POST array, but you can undo it with a little manipulation if you absolutely need to name things that way...

foreach ($_POST as $key => $value) {
    if (is_array($value)) {
        foreach ($value as $k => $v) {
            $_POST[$key.'['.$k.']'] = $v;
        }
        unset($_POST[$key]);
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top