How to destroy a static variable in php?
淡淡烟草味
淡淡烟草味 2017-05-16 12:58:25
0
1
669
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?

淡淡烟草味
淡淡烟草味

reply all(1)
过去多啦不再A梦

Documentation

如果在函数中 unset() 一个静态变量,那么在函数内部此静态变量将被销毁。但是,当再次调用此函数时,此静态变量将被复原为上次被销毁之前的值。

From: http://php.net/manual/zh/func...

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template