php funciton 中的static
时间:2011-01-05 来源:Enoch
<?php
function t(){
static $a= 0;
++ $a;
var_dump($a);
}
$i = 3;
while ($i--){
t();
}
结果 1 ,2,3
见手册 $a is initialized only in first call of function and every time the t() function is called it will print the value of $a and increment it.
static的变量初始化只执行一次
function t(){
static $a= 0;
++ $a;
var_dump($a);
}
$i = 3;
while ($i--){
t();
}
结果 1 ,2,3
见手册 $a is initialized only in first call of function and every time the t() function is called it will print the value of $a and increment it.
static的变量初始化只执行一次
相关阅读 更多 +