Php recursive output problem.

function test ()
{

static $count = 0;

$countPP;
echo $count;
if ($count < 10) {
    test();
}
$count--;
echo $count;

}
test ();
the output of this code is 123456789109876543210. I can figure out the previous output 1-109, but how does the latter output 8-0 output? in my opinion, the output should be 123456789109 and there is no loop to perform the action of $count--;echo $count;. I would like to ask where I am wrong, thank you, I am a novice, the boss is not to blame

Php
Apr.09,2021

just follow the logic of the code and think about it over and over again and you'll know the answer. When you are less than 10, the code is run recursively, and each run will be incremented and output until $count < 10 is not satisfied, and perform self-subtractive output. This will mean that 9 will enter the test () from 10 to 10, and then decrease. But don't go, because your code comes in recursively, and it has to go out layer by layer. You can go out as many layers as you come in, because you have a self-increase at the top and a self-subtraction at the bottom, so the final result will be the same as the beginning.


when another function is called, the current function is paused and in an unfinished state. The values of all variables of this function are still in memory. After executing the calling function, go back to the current function and proceed from where you left.

from: https://hellowac.github.io/pr.

Menu