Why do PHP variables need to be pre-defined before a loop in order to use it inside of (and subsequently outside of) the loop?
Assuming $results is an array of integers.
foreach ($results as $key=>$value)
{
$a = $value[0];
echo "<BR>".$a;
}
echo "<BR>".$a;
would output something like:
1
5
7
25
undefined variable $a
and I would not be able to use the variable $a (without initializing it somehow) outside of that loop because it is "undefined".
Whereas
$a;
foreach ($results as $key=>$value)
{
$a = $value[0];
echo "<BR>".$a;
}
echo "<BR>".$a;
would output something like:
1
5
7
25
25
And I would be able to use $a anywhere outside.
Seems weird to me that it almost acts like a variable scope issue.