php static

来源:互联网 发布:荣威i6 知乎 编辑:程序博客网 时间:2024/06/06 19:15
function testStatic(){
        static $a=0;
        if ($a == 0){
            echo "this is first called $a";
        }
        echo ++$a;
    }
    testStatic();   //这里每次被调用一次之后 $a的值都会增加1 相当于一个全局变量 

    testStatic();

打印结果:this is first called 01
         2