In php, global and $ GLOBALS [] are common global variables. let's take a look at a simple example to differentiate the usage of global and $ GLOBALS. According to the official explanation:
In php, global and $ GLOBALS [] are common global variables. let's take a look at a simple example to differentiate the usage of global and $ GLOBALS.
According to the official explanation:
1. $ GLOBALS ['var'] is an external global variable.
The instance code is as follows:
-
- $ Var1 = 1;
- Function test (){
- Unset ($ GLOBALS ['var1']);
- }
- Test ();
- Echo $ var1;
- ?>
2. global $ var is an external reference or pointer of $ var with the same name.
The instance code is as follows:
- $ GlobalStr = '. com ';
-
- Function globalTest (){
-
- Global $ globalStr;
-
- $ GlobalStr = 'coderbolg '. $ globalStr;
-
- Unset ($ globalStr );
-
- }
-
- GlobalTest ();
-
- Echo $ globalStr; // input: coderbolg.com