For cleaned or uninstalled php arrays, are garbage items collected?

If I disconnect the array, will its elements be collected or freed from garbage if they are not mentioned anywhere? what if i just do $ array = new array ();

$ array = array ('a' => 1);
// method 1 to clear array
unset ($ array);

method 2 to clean the array

$ array = array ('a' => 1);
// method 2 to clear array
$ array y = array ();
+5
source share
3 answers

:

        $a = array();
        $a[0] = 'a1';
        $a[1] = 'b2';

        foreach($a as $v)
            echo $v . '<br />';
        //writes content of array

        echo count($a) . '<br />';
        //writes 2

        $a = array(); //CLEAR ARRAY

        foreach($a as $v)
            echo $v . '<br />';
        //writes nothing

        echo count($a) . '<br />';
        //writes 0
+5

The following will change the array itself and leave it empty:

array_splice($myArray, 0);

And splicing documentation

+1
source

All Articles