echo "Point1, a=".$a."\n";
echo "Point1, b=".$b."\n";
if(1<2)
{
$a = 6;
$b['link'] = "here";
echo "Point2, a=".$a."\n";
echo "Point2, b[link]=".$b['link']."\n";
}
echo "Point3, a=".$a."\n";
echo "Point3, b[link]=".$b['link']."\n";
Why does the above code print out the following?
Point1, a=
Point1, b=
Point2, a=6
Point2, b[link]=here
Point3, a=6
Point3, b[link]=here
In my understanding, the scope of $a and $b should end within the curly braces { }!
Only functions and methods have their own, local scope. Other control structures (loops, conditions…) do not.
Variable scope in the PHP manual