- var_dump: documentation ( source)
<?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));