function fix_keys($array) { foreach ($array as $k => $val) { if (is_array($val)) { $array[$k] = fix_keys($val); } //recurse } return array_values($array); }
function createTree($branches) { $tree = array(); foreach ($branches as $slice_id => $slice) { if ($slice['parent_id'] == "0") { $tree[$slice_id] = $slice; unset($branches[$slice_id]); } } $tree = fix_keys(getChildren($branches, $tree)); echo '<hr>'; var_dump($branches); echo '<hr>'; return $tree; }