PHP静态变量static的示范代码演示

WBOY
Release: 2016-06-13 13:04:40
Original
683 people have browsed it

PHP静态变量static的示例代码演示

  在PHP中的变量范围里,有一个非常重要的变量―PHP静态变量static。在接下来的这篇文章中,我们将会以具体的代码示例为大家详细介绍有关PHP静态变量static的主要用法,希望对大家有所帮助。

  看看下面的例子:

  例子 演示需要PHP静态变量static的例子

  

  本函数没什么用处,因为每次调用时都会将 $w3sky 的值设为 0 并输出 "0"。将变量加一的 $w3sky++ 没有作用,因为一旦退出本函数则变量 $w3sky 就不存在了。要写一个不会丢失本次计数值的计数函数,要将变量 $w3sky 定义为静态的:

  例子 使用PHP静态变量static的例子

  

  现在,每次调用 Test() 函数都会输出 $w3sky 的值并加一。

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!