global is used to bring a variable from a higher scope into a function where it wouldn't normally be defined.
So if you have this on a page"
<?php
$mylocalvariable = "defined!";
function writeLocalVariable() {
echo($mylocalvariable);
}
writeLocalVariable();
This will error: "$mylocalvariable is not defined"
Because by default the scope of the variable means it isn't carried into the function. To solve that problem you can use:
<?php
$mylocalvariable = "defined!";
function writeLocalVariable() {
global $mylocalvariable;
echo($mylocalvariable);
}
writeLocalVariable();
By declaring the variable global in the function it becomes available to use.