These example illustrate laserlight's suggestions:
$foo = "bar";
function fooBar1() {
// this will echo nothing, or ""
echo $foo;
}
function fooBar2() {
// this will echo "bar"
global $foo;
echo $foo;
}
function fooBar3($foo) {
// this will echo "bar"
echo $foo;
}
In other words, use the global keyword INSIDE the function.
This may be a little confusing. In many languages, such as C, variables are always global unless otherwise overwritten within a function. It's easier in PHP to think of all variables being global, but local within a function. If you want to use the global "version" of the variable, you tell that function to "go ahead and use the global variable" by using the global keyword.
Incidentally, the opposite of this is the keyword "static." Ordinarily, a local variable inside a function is only available to the function. If you want the variable to be available after the function is done, then you would use the "static" keyword.
Check out the PHP manual for more information.