What is the difference between a PHP static global variable and a normal global variable?
<?phpfor ($i =1; $i <5; $i + +) { //$glo =1; Static $glo =1; $glo + +;} Echo $glo;? >
In the above example, $glo is a global scope, and the output is different from the non-static keyword, it turns out that the use of static global variables can be used, but the PHP manual only talks about using static variables in functions, as well as static member properties and methods of classes. Does not involve the concept of static global variables, the data found on the network are basically c,c++,java to the static global variable interpretation, very little involved in PHP. I don't know if the static variables in these languages are consistent with PHP.
I now know that both global variables and static variables are placed in the same area of memory. Who else to explain, if PHP has the concept of static global variables, then it is different from ordinary global variables?
------Solution--------------------
The difference is right here.
static $glo =10;echo $glo;//1for ($i =1; $i <5; $i + +) {// echo $glo; static $glo =1; $glo + +;} echo $glo;//5