PHP » Predefined Variables » Globals

Syntax:
$GLOBALS

The $GLOBAL autoglobal contains all variables available in the current scope. Global variables can be added directly to the array, or the keyword global can be used, as in the example.

Examples

Code:
<?php

$a = 5;
$b = 5;

function change()
{
   $a += 5;
}

function change_global()
{
   global $b;

   $b += 5;
}

change();
change_global();
print "a: $a <br>";
print "b: $b <br>";

?>
Output:
a: 5
b: 10
Explanation:

The function change() cannot access the variable a, since it is not in the global scope.