How to get current recursion level in a PHP function

前端 未结 5 1938
灰色年华
灰色年华 2021-01-18 05:20

How to get current recursion level in a PHP function ? I mean, is there any \"magical\" (or eventually normal) function like this :

function doSomething($thi         


        
5条回答
  •  醉酒成梦
    2021-01-18 05:39

        function doSomething($things) {
    static $level = 0;
        if (is_array($things)) {
            foreach ($things as $thing) {
    $level++;
                doSomething($thing);
            }
        } else {
            // This is what I want :
            echo $level
        }
    }
    

提交回复
热议问题