本文介绍了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 superglobal 数组,表示可作为数组访问的全局变量表.因为它是超全局性的,所以随处可见.

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

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

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

然后您问:

错了,您可以使用$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有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 08:21