For cleared or unset php arrays, are elements garbage collected?

后端 未结 3 1531
执笔经年
执笔经年 2021-01-13 06:26

if I unset an array, would its elements be garbage collected or freed up assuming they are not referenced in anywhere else? what if I simply do $array =new array();

3条回答
  •  梦毁少年i
    2021-01-13 07:02

    Following simple code answers the question:

            $a = array();
            $a[0] = 'a1';
            $a[1] = 'b2';
    
            foreach($a as $v)
                echo $v . '
    '; //writes content of array echo count($a) . '
    '; //writes 2 $a = array(); //CLEAR ARRAY foreach($a as $v) echo $v . '
    '; //writes nothing echo count($a) . '
    '; //writes 0

提交回复
热议问题