Home  >  Article  >  Backend Development  >  PHP静态变量static的示范代码演示

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

WBOY
WBOYOriginal
2016-06-13 13:04:40684browse

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

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

  看看下面的例子:

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

  

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

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

  

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

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
Previous article: PHP 顶用java Next article: php仿jQuery统制dom | php采集