Home > php教程 > php手册 > php中global和$GLOBALS[]用法区别

php中global和$GLOBALS[]用法区别

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 10:15:14
Original
1227 people have browsed it

php中global和$GLOBALS[]是比较常见全局变量了,下面我们给大家看一个简单的实例,来区别一下global和$GLOBALS[]用法吧。

根据官方的解释是 :

1.$GLOBALS['var']是外部的全局变量本身。

 代码如下 复制代码

$var1 = 1; 
function test(){ 
     unset($GLOBALS['var1']); 

test(); 
echo $var1; 
?> 


2.global $var是外部$var的同名引用或者指针。

 

 代码如下 复制代码
$globalStr = '.com';
 
function globalTest(){
 
 global $globalStr;
 
 $globalStr = 'coderbolg'.$globalStr;
 
 unset($globalStr);
 
}
 
globalTest();
 
echo $globalStr; //输入: coderbolg.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template