We are using
If the PHP keyword global is used inside the function, it indicates that the variable used in the function is global, and the global variable is available throughout the page. For example
- $ Conf = 1;
- Function conf_test (){
- Global $ conf;
- Return ++ $ conf;
- }
- Echo conf_test ()."< Br>";
- Echo conf_test ()."< Br>";
Output:
2
3
If there is no global $ conf;, the output will be 1. The global keyword of PHP is used to declare that $ conf in the function is not local, but global. Or, the $ conf defined in the function is not a variable in the function, but the $ conf defined outside the function (that is, $ conf = 1. in fact, if $ GLOBALS array is used here, it is easier to understand.
We declare a variable $ conf on the page, which is equivalent to defining a $ GLOBALS ['conf'] in the $ GLOBALS array. This $ GLOBALS is globally visible. Therefore, the above Code is written in the $ GLOBALS format.
- $conf = 1;
- function conf_test() {
- return ++$GLOBALS['conf'];
- }
- echo conf_test()."<br>";
- echo conf_test()."<br>";
Output:
2
3
PHP keyword global