0

is there any way that I can get current depth of array? So far, I had no luck with this..

My code:

use app\components\TreeView;
use app\models\Kategorije;
$tree = TreeView::getMenu();

function recursion($stablo,&$indent) {
    $indent++; // Try to get depth of current array
    foreach ($stablo as $value) {
        foreach ($value as $key => $value) {
            $indent_str = str_repeat("-", $indent);
            echo $indent.$value['label'].'<br>';
            if (!empty($value['items'])) {
                recursion($value['items'],$indent);
            }
        };
    }
}
$indent = 0;
recursion($tree,$indent);

I need that depth for indentation...

user3002173
  • 135
  • 1
  • 8

0 Answers0