I don't think you can disable this feature without recompiling php.
I want to warn you about reconstructing the original variable names by walking the multi dim array. You can't fully reconstruct the names because php renames certain characters. For example, php doesnt allow certain characters in a top-level array key in $_POST/$_GET/etc... and so it replaces the char with an underscore. This makes it impossible to differentiate between a.b
a b
a[b
as they all show up as a_b
. In addition, there's longstanding bugs related to parsing the array syntax of request variables that causes this behavior. Here's a bug report I filed a few years ago https://bugs.php.net/bug.php?id=48597 which is unlikely to ever be fixed.
In addition, magic_quotes_gpc
has sunk its talons into the array keys if that setting is enabled.
But if you're ok with these aforementioned edge cases failing, then you could reconstruct the array as follows:
$ritit = new RecursiveIteratorIterator(new RecursiveArrayIterator($_POST));
$result = array();
foreach ($ritit as $k => $leafValue) {
if ($ritit->getDepth() > 0) {
$path = array($ritit->getSubIterator(0)->key());
foreach (range(1, $ritit->getDepth()) as $depth) {
$path[] = sprintf('[%s]', $ritit->getSubIterator($depth)->key());
}
$result[ join('', $path) ] = $leafValue;
} else {
$result[$k] = $leafValue;
}
}
print_r($result);