$ GLOBALS ["test"]]与全局$ test有什么区别? [英] Is there any differents between $GLOBALS["test"] and global $test?

查看:91
本文介绍了$ GLOBALS ["test"]]与全局$ test有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以让我知道

$GLOBALS["test"] and global $test

,如果我使用$GLOBALS["test"]而不是$_SESSION['test'],是否有意义?

and, will it make sense that, if i use $GLOBALS["test"] instead of $_SESSION['test']?

推荐答案

并且,如果我使用,是否有意义 $ GLOBALS ["test"]代替 $ _SESSION ['test']?

and, will it make sense that, if i use $GLOBALS["test"] instead of $_SESSION['test']?

否, 会话 是与全局可用变量不同.

No, session is different thing from a variable that is available globally.

$ GLOBALS

包含以下内容的关联数组 引用所有变量 当前在全球范围内定义 的脚本.变量名称是 数组的键.

An associative array containing references to all variables which are currently defined in the global scope of the script. The variable names are the keys of the array.

http://php.net/manual/en/reserved.variables .globals.php

说明:

$GLOBALS是整个脚本中可用的关联数组,无需使用global $test

$GLOBALS is an associative array available throughout your script, there is no need to use global $test

注意:这是一个超级全局",或 自动全局变量.这 只是意味着它在 脚本中的所有作用域.那里 不需要做全局变量到 在函数或方法中访问它.

Note: This is a 'superglobal', or automatic global, variable. This simply means that it is available in all scopes throughout a script. There is no need to do global $variable; to access it within functions or methods.

这篇关于$ GLOBALS ["test"]]与全局$ test有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆