PHP静态全局变量跟普通全局变量有什么区别

WBOY
Release: 2016-06-13 13:17:54
Original
1006 people have browsed it

PHP静态全局变量和普通全局变量有什么区别?
for($i=1;$i   //$glo=1;
  static $glo=1;
  $glo++;
}
echo $glo;
?>
在上例中$glo是全局作用域的,并且加与不加static关键字输出结果是不同的,事实证明是可以使用静态全局变量这个用法的,但是PHP手册里只谈到在函数里使用静态变量,以及类的静态成员属性和方法。并没有涉及到静态全局变量这个概念,在网络上搜索到的资料基本上都是C,C++,JAVA的对静态全局变量的解释,很少有涉及PHP。我不知道这些语言中的静态变量是否和PHP是一致的。
我目前知道全局变量和静态变量都放在内存同一区域里。还请哪位讲解一下,如果PHP里有静态全局变量这个概念的话,那么它和普通的全局变量有哪些区别?

------解决方案--------------------
区别就在这里

static $glo=10;
echo $glo;//1
for($i=1;$i// echo $glo;
static $glo=1;
$glo++;
}
echo $glo;//5

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 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!