That’s a good question. According to my knowledge, recursion in PHP works by functions calling themselves, creating a new scope each time, but unless you return the result of the deeper calls, the outer ones won’t get updated values.
Here’s a related Stack Overflow thread about limiting recursion depth in PHP: https://stackoverflow.com/questions/74205907/how-letting-services-to-limit-recursive-function-in-php