请友人帮忙讲解一下$GLOBALS的含义:function test() {$foo = "local variable";echo '$foo in global scope:' .$GLOBALS["foo"] ."\n";echo '$foo in current scope:' .$foo ."\n";}$foo = "Example content";test();上面输出$foo in global scope:Ex

来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/22 05:25:52
请友人帮忙讲解一下$GLOBALS的含义:functiontest(){$foo="localvariable";echo''$fooinglobalscope:''.$GLOBALS["foo"]."\

请友人帮忙讲解一下$GLOBALS的含义:function test() {$foo = "local variable";echo '$foo in global scope:' .$GLOBALS["foo"] ."\n";echo '$foo in current scope:' .$foo ."\n";}$foo = "Example content";test();上面输出$foo in global scope:Ex
请友人帮忙讲解一下$GLOBALS的含义:
function test() {
$foo = "local variable";
echo '$foo in global scope:' .$GLOBALS["foo"] ."\n";
echo '$foo in current scope:' .$foo ."\n";
}
$foo = "Example content";
test();
上面输出
$foo in global scope:Example content
$foo in current scope:local variable
上面代码$GLOBALS["foo"]输出为啥是"Example content"而不是 "local variable"呀?

请友人帮忙讲解一下$GLOBALS的含义:function test() {$foo = "local variable";echo '$foo in global scope:' .$GLOBALS["foo"] ."\n";echo '$foo in current scope:' .$foo ."\n";}$foo = "Example content";test();上面输出$foo in global scope:Ex
$GLOBALS为全局变量,读取函数外的变量,函数外的变量名为$foo,所以要用$GLOBALS["foo"];
而函数内的普通变量直接用$foo就行