What is the difference between static and common global variables in PHP? & Lt ;? Phpfor ($ i1; $ I & lt; 5; $ I ++) {& nbsp; $ glo1; & nbsp; static $ glo1; & nbsp; $ glo ++ ;} echo $ glo ;? & Gt; in the preceding example, $ glo is globally scoped, and the output result is different from the output result without the static keyword, it turns out that PHP static global variables are different from normal global variables?
For ($ I = 1; $ I <5; $ I ++ ){
// $ Glo = 1;
Static $ glo = 1;
$ Glo ++;
}
Echo $ glo;
?>
In the preceding example, $ glo is globally scoped and the output result is different from that without the static keyword. it turns out that static global variables can be used, however, the PHP manual only talks about using static variables in functions and static member attributes and methods of classes. The concept of static global variables is not involved. the materials searched on the network are basically C, C ++, and JAVA's explanation of static global variables, rarely involving PHP. I don't know if the static variables in these languages are consistent with those in PHP.
I currently know that both global variables and static variables are in the same area of memory. Which of the following explains the differences between static global variables and common global variables in PHP?
------ Solution --------------------
The difference is here
Static $ glo = 10;
Echo $ glo; // 1
For ($ I = 1; $ I <5; $ I ++ ){
// Echo $ glo;
Static $ glo = 1;
$ Glo ++;
}
Echo $ glo; // 5