Home > php教程 > php手册 > body text

php的global

WBOY
Release: 2016-06-13 10:48:11
Original
886 people have browsed it

$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之后,变量就是全局的啦,当然,就算函数中已经定义了相同名字的局部变量,那也用不上“它”了,而变成引用了之前定义的。 


摘自 流窜
Related labels:
source:php.cn
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!