function testStatic(){
unset($arr);
static $arr=array();
array_push($arr, 1,2,3);
var_dump($arr);
}
testStatic();
//array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) }
testStatic();
//array(6) { [0]=> int(1) [1]=> int(2) [2]=> int(3) [3]=> int(1) [4]=> int(2) [5]=> int(3) }
When executing testStatic() for the second time, $arr cannot be destroyed correctly using unset; how can I completely destroy the static variable?
过去多啦不再A梦2017-05-16 13:00:25
Documentation
如果在函数中 unset() 一个静态变量,那么在函数内部此静态变量将被销毁。但是,当再次调用此函数时,此静态变量将被复原为上次被销毁之前的值。
From: http://php.net/manual/zh/func...