- 静态变量放在函数内
<?phpheader('content-type:text/html;charset=utf-8');function fun(){static $num=1;$num++;echo $num,'<br>';}fun();fun();
?>
静态变量放在函数内,作用域没变,生命周期变了,页面执行完毕才销毁,静态变量只能被初始化一次
<?phpheader('content-type:text/html;charset=utf-8');function fun(){static $num=1;$num++;echo $num,'<br>';}function fun2(){$num++;echo $num,'<br>';}fun();fun2();
?>