Detailed explanation of php static variables_php static variables and global static variables examples

WBOY
Release: 2016-07-25 08:52:39
Original
993 people have browsed it
  1. function test()
  2. {
  3. static $var = 5; //static $var = 1+1; will report an error
  4. $var++;
  5. echo $var . ' ';
  6. }
  7. test() ; //2
  8. test(); //3
  9. test(); //4
  10. echo $var; //Error: Notice: Undefined variable: var
Copy code

Part 2, php static variables Global type, let’s understand it through examples.

  1. //Global variables themselves are static storage methods, and all global variables are static variables

  2. function static_global(){
  3. global $glo;
  4. $glo++;
  5. echo $glo.'
    ';
  6. }

  7. static_global(); //1

  8. static_global(); //2
  9. static_global(); //3
  10. echo $glo . '
Copy code

Tips: Static global variables are not used much.



source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!