What is the difference between static PHP global variables and common global variables?

Source: Internet
Author: User
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

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.