About more complex situation using global variables..
Let's say we have two files:
a.php
<?php
function a() {
include("b.php");
}
a();
?>
b.php
<?php
$b = "something";
function b() {
global $b;
$b = "something new";
}
b();
echo $b;
?>
You could expect that this script will return "something new" but no, it will return "something". To make it working properly, you must add global keyword in $b definition, in above example it will be:
global $b;
$b = "something";