Why is the last $ a value 0 in the above recursion? Isn't it 1?

Source: Internet
Author: User
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 $ ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.