3v4l.org

run code in 300+ PHP versions simultaneously
<?php $a = ['foo' => 'bar']; $b = ['foo' => ['bar' => null, 'buz' => null]]; // you need to fix this or special case int keys $c = ['foo' => ['bar' => 'buz']]; function treeMe($array) { if (!is_array($array) || !$array) { return $array; } $tmp = []; foreach ($array as $k => $v) { $tmp[$k] = treeMe($v); } return $tmp; } var_dump(treeMe($a)); var_dump(treeMe($b)); var_dump(treeMe($c));

preferences:
46.99 ms | 402 KiB | 5 Q