Unlike local variables, a global variable can be accessed in any part of the program. Global Variable Declaration in PHP is quite simple, if we want a variable to be accessible from within a function, we can use the global keyword.
Global Variable can be accessed anywhere in our script, whether inside or outside a function. In order to modify a global variable, it must be explicitly declared to be global in the function in which it is to be modified.
Superglobals are built-in variables which are always available in all scopes throughout the script and hence it is not required to declare global $variable to access them within functions or methods.
These superglobal variables are:
It references all variables available in global scope.
This will produce following result
It is an array which contains information like headers, paths,and script locations.
This will produce following result
It is an associative array of variables passed to the current script through URL parameters.
Suppose the user has made an entry https://example.com/?myname=Bill
This will produce following result
It is an associative array of variables passed to the current script through HTTP POST method.
Suppose the user has made an entry posted hostname = Jim
This will produce following result
It is an associative array of variables passed to the current script through HTTP Cookies.
Suppose the "myname" cookie has already been set
This will produce following result