Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP:在递归函数中查找当前数组的深度_Php - Fatal编程技术网

PHP:在递归函数中查找当前数组的深度

PHP:在递归函数中查找当前数组的深度,php,Php,有什么方法可以得到阵列的当前深度吗? 到目前为止,我在这件事上运气不好 我的代码: 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 $va

有什么方法可以得到阵列的当前深度吗? 到目前为止,我在这件事上运气不好

我的代码:

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);
使用app\components\TreeView;
使用app\models\Kategorije;
$tree=TreeView::getMenu();
函数递归($stablo,&$indent){
$indent++;//尝试获取当前数组的深度
foreach($stablo作为$value){
foreach($key的值=>$value){
$indent_str=str_repeat(“-”,$indent);
回显$indent.$value['label'].
'; 如果(!empty($value['items'])){ 递归($value['items',$indent); } }; } } $indent=0; 递归($tree,$indent);

我需要缩进的深度…

发布你的数组结构和预期输出不要使用&$indent作为参考=>函数递归($stablo,$indent)@alexisteters谢谢,这解决了我的问题!:)