How to get the current recursion level in a PHP function? I mean, is there any βmagicβ (or, ultimately, normal) function:
function doSomething($things) { if (is_array($things)) { foreach ($things as $thing) { doSomething($thing); } } else {
I know that I can use another function argument ( $level in this example):
function doSomething($things, $level = 0) { if (is_array($things)) { foreach ($things as $thing) { $level++; doSomething($thing, $level); } } else { echo $level; } }
But I want to know if there is a built-in function (or trick) for this. Maybe something with debug_backtrace() , but it doesn't seem like a simple or quick solution.
I did not find this information, perhaps it simply does not exist ...
source share