Function can see variable

Your function can see only three types of variables:

1- Those which were defined in the function body (local variables);

function myFunc() { 
    $foo = 'bar'; 
    echo $foo; 
}

2- Those which were defined outside the function and declared as global inside the function:

$foo = 'bar';
function myFunc() {
    global $foo;
    echo $foo;
}

3- Those which were passed to the function as arguments:

$foo = 'bar';
function myFunc($param){
    echo $param;
}
myFunc($foo);

So, to make external variables visible by the function you should either declare them as global in the function body (that is a bad practice and not recommended usually) or pass them as arguments (standard practice).