For the following recursion, why is the last $ A value 0? Isn't it 1?
PHP Code
'; $a + +; if ($a < 2) { Test (); } $a--; return $a;}? >
For the above recursion, why is the last $ A value 0? Isn't it 1?
I debugged with debugger and found that the order of operation was:
Order: 4―5―6―7―8―4―5―6―7―10―11―10―11
$a value: 0―0―1―1―1―1―1―2―2―1―1―0―0
The result of the last run output is
0
1
0
Just want to ask, why do 10 rows and 11 rows run two times?
Thanks, man.
------Solution--------------------
This execution is sequential
How many times do you say that?
4 static $a = 0;//This is line 4th.
5 echo $a. '
';
6 $a + +;
7 if ($a < 2) {
8 Test ();
4 static $a = 0;//This is line 4th.
5 echo $a. '
';
6 $a + +;
7 if ($a < 2) {
3 ·
Ten $a--;
return $a;
3 ·
Ten $a--;
return $a;
------Solution--------------------
PHP code
function Test () {static $a = 0;//here is line 4th------------ ------------(1) echo $a. '
'; $a ++;/* Note that the next line in the non-commented code, the return value must be defined at (1) *//* If you want to get the expected return result 1, if ($a < 2) {return Test (); }*/$a--; return $a;}