I\'ve got a nested tree structure which is based on the array below:
Array
(
[1] => Array
(
[id] => 1
[parent] => 0
[n
Solved it! Added this function to my class:
private function cleanTree(&$arr){
foreach($arr as $key => &$item) {
if(!$item["child"] && empty($item["basename"])){
unset($arr[$key]);
}elseif(is_array($item["child"])){
if(count($item["child"]) == 0){
unset($arr[$item["id"]]);
}else{
$this->cleanTree($item["child"]);
}
}
}
}
To remove unnecessary elements on the ROOT level(s) as well as anyone else, just run the above twice.