Give a short note on variable scope in functions

The scope of a variable is determined based on the context in which is defined. i.e. local or global. In PHP global variables must be declared global inside a function if they are going to be used in that function.

Example: The script below will not produce any result because "x" ‘s scope is outside the function. If the variable is declared as global, it can be used from anywhere in the script.

$x = 10; //global
Functi
on sample()
{
Echo $x;
}
Test();
?>