Home > Backend Development > PHP Tutorial > Example of using php global variable global

Example of using php global variable global

WBOY
Release: 2016-07-25 09:03:29
Original
891 people have browsed it
  1. $a = 1;
  2. $b = 2;
  3. function Sum()
  4. {
  5. global $a, $b; //Declared as a global variable inside
  6. $b = $a + $b;
  7. }
  8. Sum();
  9. echo $b;
  10. ?>
Copy code

Result: 3 If there is no global variable global, the values ​​​​of $a and $b cannot be obtained within the method, so if you want to use external variables in the method, you need to declare the variable as a global variable first, and then you can use it.



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