var libary={$f}=tree("$dir/$f",$depth+1); } else{ $json->{$f}=array("Error: Too Deep"=>array("Infinite loop prevention"=>array())); } } else{ array_push($files,$f); } } if(count($files)>0){ $json->{"/"}=$files; } return $json; } echo json_encode(tree('library',0)); ?>