Hi, all,
foreach($array as $k =$v) {
$foo = ...;
}
echo $foo;
Is it allowed to access the $foo variable that is created within the
loop from outside of the loop? I think it isn't allowed, because
according to the rule stated in PHP manual(http://www.php.net/manual/
en/language.variab les.scope.php): The scope of a variable is the
context within which it is defined, the $foo variable is defined
inside the loop, so its scope should limit within that loop. But the
test result of such script shows that I can access the $foo variable
from outside of the loop correctly. WHY? I'm a PHP newbie, Could
somebody help me out? Thanks in advance.
foreach($array as $k =$v) {
$foo = ...;
}
echo $foo;
Is it allowed to access the $foo variable that is created within the
loop from outside of the loop? I think it isn't allowed, because
according to the rule stated in PHP manual(http://www.php.net/manual/
en/language.variab les.scope.php): The scope of a variable is the
context within which it is defined, the $foo variable is defined
inside the loop, so its scope should limit within that loop. But the
test result of such script shows that I can access the $foo variable
from outside of the loop correctly. WHY? I'm a PHP newbie, Could
somebody help me out? Thanks in advance.
Comment