Memory address of global and local variable

元气小坏坏 提交于 2019-12-11 20:07:46

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!