PHP – Global Variables – Superglobals

Superglobals are variables that are always available in all scopes.
Superglobals always accessible, regardless of scope – and you can access them from any function, class or file without having to do anything special.

The PHP superglobal variables are:

$GLOBALS
$_SERVER
$_REQUEST
$_POST
$_GET
$_FILES
$_ENV
$_COOKIE
$_SESSION

$GLOBAL

$GLOBAL is a PHP super global variable which is used to access global variables from anywhere in the PHP script (also from within functions or methods).

In the next example, since z is a variable present within the $GLOBALS array, it is also accessible form outside the function!

<?php 

$x = 75;
$y = 25; 

function addition()
{
$GLOBALS['z'] = $GLOBALS['x'] + $GLOBALS['y'];
}

addition();
echo $z; // Output: 100

?>