For the above recursion, why is the last $ A value 0? Not 1?

Source: Internet
Author: User
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) {
9}
Ten $a--;
return $a;
9}
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;}
  • Related Article

    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.