问题
I've just used local and global variable with the same name. Local variable located in a function. The code snippet is as below (in PHP):
$var = 10;
function fn ()
{
$var = 20;
return $var;
}
fn ();
echo $var;
If the global variable contain 10 then after calling the fn() how variable $var remain unchanged where $var is assigned to 20 in the function. Both have same name, my question is how memory track which one is global and which one is local?
来源:https://stackoverflow.com/questions/33587224/memory-address-of-global-and-local-variable