Static variables only exist in the local function scope, but their values are not lost when program execution leaves this scope. Take a look at the following example:
Copy the code The code is as follows:
function test(){
static $a= 0;
$a++;
echo $a;
}
test();//1
test();//2
test( );//3
Note: Static variables can be declared as shown in the above example. Assigning it with the result of an expression in a declaration will result in a parsing error.
Copy code The code is as follows:
static $a=0+1;
static $a=sqrt(121 );
The above assignment method will report an error. If you don’t believe me, try it.
http://www.bkjia.com/PHPjc/327941.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327941.htmlTechArticleStatic variables only exist in the local function scope, but when the program execution leaves this scope, its value does not lost. Take a look at the example below: Copy the code The code is as follows: function test(){ static...