<?phpphp
test();ide
$num = 5;spa
function test() {it
static $num = 0;io
$num++;function
echo $num."\r\n";class
}test
test();变量
test();方法
echo "外部=".$num;
?>
输出结果:
1
2
3
外部=5
静态(static)局部变量 不像 动态变量同样,调用就存在,静态变量是始终存在的,也就是即便你退出了这个方法,但当下次访问的时候,它仍是保留了上次的值,这是静态变量的特性。