Variable Scope
$a = 1;
function Test(){ /* reference to local scope variable*/
echo "\$a - Value (local scope) : $a \n";
}
Test();
$a = 1;
$b = 1;
function Test2(){
global $a, $b;
$b = $a + $b;
}
Test2();
echo "Globally changed \$b $b<br>\n";
$a - Value (local scope) :
Globally changed $b 2
// Useless Function it does nothing
function Test3(){
$a = 0;
echo $a;
$a++;
}
// This function allows us to increment a counter
function Test4(){
static $a = 0;
echo $a;
$a++;
}
Test3();Test3();Test3();
echo ";";
Test4();Test4();Test4();
000;012
echo "Variable variable<br />\n";
$a = "hello"; // How to set a normal variable
$$a = "world";
echo "$a ${$a}";
echo "$a $hello"; // Produce exactly the same output
Variable variable
hello world
hello world