$ GLOBALS [var] is an external global variable, and global $ var is an external reference or pointer with the same name as $ var.
1. Comparison of examples
Example 1:
The code is as follows:
$ Var1 = 1;
Function test (){
Unset ($ GLOBALS ['var1']);
}
Test ();
Echo $ var1;
?>
Because $ var1 is deleted, nothing is printed.
Example 2:
The code is as follows:
$ Var1 = 1;
Function test (){
Global $ var1;
Unset ($ var1 );
}
Test ();
Echo $ var1;
?>
Accidentally printed 1. It indicates that only alias reference is deleted, and its value is not changed.
II. Explanation
Global $ var is actually an alias for calling an external variable & $ GLOBALS ['var.
$ Var1 and $ GLOBALS ['var1'] in the above code refer to the same variable, rather than two different variables.
The global variables of PHP are a little different from those of C. In C, global variables take effect in functions unless they are shrouded in local variables. This may cause some problems. some may carelessly change a global variable. Global variables in PHP must be declared as global in the function.
PHP's Global variable defines Global variables, but this Global variable is not applied to the entire website, but to the current page, including all files including include or require.
III. Conclusion
1. $ GLOBALS ['var'] is an external global variable.
2. global $ var is an external reference or pointer with the same name as $ var.