-
- function test()
- {
- static $var = 5; //static $var = 1+1; will report an error
- $var++;
- echo $var . ' ';
- }
-
- test() ; //2
- test(); //3
- test(); //4
- echo $var; //Error: Notice: Undefined variable: var
Copy code
Part 2, php static variables Global type, let’s understand it through examples.
-
-
//Global variables themselves are static storage methods, and all global variables are static variables
- function static_global(){
- global $glo;
- $glo++;
- echo $glo.'
';
- }
static_global(); //1
- static_global(); //2
- static_global(); //3
- echo $glo . '
-
Copy code
Tips: Static global variables are not used much.
|