global keyword and the $GLOBALS superglobal array.
The global Keyword
The global keyword is used inside a local scope to import a variable from the global symbol table into the local symbol table.
global keyword creates a reference (alias) to the global variable. The statement global $value; is semantically equivalent to:
unset() function on a variable imported via the global keyword only severs the local reference; it does not destroy the variable in the global symbol table.
The $GLOBALS Superglobal Array
$GLOBALS is a built-in associative array containing references to all variables currently defined in the global scope. The keys of the array are the names of the global variables, and the values are the contents of those variables.
Because $GLOBALS is a superglobal, it is automatically available in all scopes without requiring explicit importation.
global keyword, $GLOBALS accesses the actual global variable directly rather than creating a local alias. Consequently, using unset() on an element within the $GLOBALS array will completely destroy the variable in the global symbol table.
Variable Variables and Global Scope
When using variable variables (dynamic variable names) with theglobal keyword, the variable holding the dynamic name is resolved in the local scope to determine which global variable to import.
Tired of Poor PHP Skills? Fix That With Deep Grasping!Learn More





