码迷,mamicode.com
首页 > 其他好文 > 详细

static作用域

时间:2018-05-21 14:51:06      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:etag   static   tags   作用   strong   static作用   cti   reserve   str   

当一个函数完成时,它的所有变量通常都会被删除。然而,有时候您希望某个局部变量不要被删除。

要做到这一点,请在您第一次声明变量时使用 static 关键字:

<?php
  function myTest() {
    static $x=0;
    echo $x;
    $x++;
  }
  myTest();
  myTest();
  myTest();
?>

static作用域

标签:etag   static   tags   作用   strong   static作用   cti   reserve   str   

原文地址:https://www.cnblogs.com/alexguoyihao/p/9066473.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!