Why is the last $ a value 0 in the recursion below? Isn't it 1? PHPcode & lt ;? PhpechoTest (); functionTest () {static $ a0; here is the 4th line echo $. & lt; br & gt; $ a ++; if ($ a & lt; 2) {Test () ;}about the recursion below, why is the last $ a value 0? Isn't it 1?
PHP code
'; $ A ++; if ($ a <2) {Test () ;}$ a --; return $ a ;}?>
Why is the last $ a value 0 in the above recursion? Isn't it 1?
I used Debugger for debugging and found that the running sequence is:
Sequence: 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 output result is
0
1
0
I just want to ask, why do 10 lines and 11 lines run twice?
Thank you!
------ Solution --------------------
This execution is sequential.
How many times have you said this?
4 static $ a = 0; // here is 4th rows
5 echo $ .'
';
6 $ a ++;
7 if ($ a <2 ){
8 Test ();
4 static $ a = 0; // here is 4th rows
5 echo $ .'
';
6 $ a ++;
7 if ($ a <2 ){
9}
10 $ --;
11 return $;
9}
10 $ --;
11 return $;
------ Solution --------------------
PHP code
Function Test () {static $ a = 0; // Here is the 4th rows ------------------------ (1) echo $ .'
'; $ A ++;/* Note that the upper and lower lines of the non-annotated code must be (1) definition * // * if you want to obtain expected return result 1, if ($ a <2) {return Test () ;}*/$ --; return $ ;}