Home >php教程 >php手册 >php的global

php的global

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-13 10:48:11958browse

$A="hello";

function print_a(){
 
  $A="php&mysql";
  global $A;
  $A="mytest";
  echo $A;
}

echo $A;
echo "
";
print_a();
echo "
";
echo $A;
?>

输出结果:

hello
mytest
mytest

最开始还有点疑惑哦,不过呢这个程序和输出结果很清楚地说明了什么事global.

在函数定义中,声明global之后,变量就是全局的啦,当然,就算函数中已经定义了相同名字的局部变量,那也用不上“它”了,而变成引用了之前定义的。 


摘自 流窜
Statement:
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