3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $wtf = array(); $a = parse_str("elements[55][e_id]=1", $tmp_save1); $wtf = array_merge_recursive_new($wtf, $tmp_save1); $b = parse_str("elements[55][wtf]=2", $tmp_save2); $wtf = array_merge_recursive_new($wtf, $tmp_save2); print_r($wtf); function array_merge_recursive_new() { $arrays = func_get_args(); $base = array_shift($arrays); foreach ($arrays as $array) { reset($base); //important while (list($key, $value) = @each($array)) { if (is_array($value) && @is_array($base[$key])) { $base[$key] = array_merge_recursive_new($base[$key], $value); } else { $base[$key] = $value; } } } return $base; }
based on juq5C
Output for 4.3.0 - 7.1.0
Array ( [elements] => Array ( [55] => Array ( [e_id] => 1 [wtf] => 2 ) ) )