Вопрос

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.

Это было полезно?

Решение

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]);
    }
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top