GLOBALS和GLOBAL有什么区别? [英] what is the difference between GLOBALS and GLOBAL?

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

问题描述

在PHP中,我想知道GLOBAL和GLOBALS之间的区别.

In PHP I want to know the differences between the GLOBAL and GLOBALS.

一些例子:

print_r($GLOBALS);

推荐答案

与同一事物有两个不同的方面:全局变量.

That are two different things related to the same: global variables.

$GLOBALS -PHP

$GLOBALS - PHP superglobal array representing the global variable table accessible as an array. Because it's a superglobal, it's available everywhere.

一个关联数组,其中包含对脚本全局范围中当前定义的所有变量的引用.变量名是数组的键.

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.

global -将特定的全局变量导入局部变量的关键字桌子.

global - Keyword to import a specific global variable into the local variable table.

然后您问:

但是为什么我们不能使用$GLOBALS访问会话和cookie变量?

But why we cant access the session and cookie variables by using $GLOBALS?

错了,您可以使用$GLOBALS访问会话和cookie变量:

That's wrong, you can access session and cookie variables by using $GLOBALS:

$GLOBALS['_SESSION']['session_variable_name']

但是 $_SESSION 也是超全局变量,因此您无需使用任何$GLOBALS也不能global从任何地方访问会话变量:

However $_SESSION is a superglobal as well, so you don't need to use either $GLOBALS nor global to access session variables from everywhere:

$_SESSION['session_variable_name']

$_COOKIE 也是如此.

Same applies to $_COOKIE.

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

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