This paper
Public Function Digui ($i) { if ($i = = ' 1 ') { echo "*"; echo "<br>"; return; } else{ $this->digui ($i-1); for ($j =1; $j <= $i; $j + +) { echo "*"; } echo "<br>"; } } Call $this->digui (3), result ****** function Digui2 ($n) { echo $n. "; if ($n >0) { $this, Digui2 ($n-1); } else{ echo "<-->"; } echo $n. " "; }
Call $this->digui2 (3);
Results
3 2 1 0 <-->0 1 2 3
Recursive functions perform anatomical examples (reproduced by others)
Look at the following code:
<?phpfunction One ($num) {echo $num; ($num-1); Echo $num;} function double ($num) {echo $num; three ($num-1); Echo $num;} Function three ($num) {echo $num;} One (3);? >
The above code to decompose the test () function, we think:
When executing the one (3) function, the same as the test () function, the first to output 3, and then call the two (2) function,
Note that at this time there is no output of the following 3,
and then go, Execute the two (2) function, output 2, call the three (1) function, again, there is no time to output the following 2,
Execute three (1), direct output 1, do not call other functions,
at this point, we would like to just two () function is not yet done, good, Then the two () function does not complete the part, after the two () function is finished, that is, the output of the following 2, and then start to execute the one () function is not finished, that is, the output of the following 3, when all functions are completed.
then the output is:
3 2 1 2 3