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();
The following will modify the array itself and leave it empty:
array_splice($myArray, 0);
And the Splice Documentation
Check-out php < 5.3 garbage collection, do array values need to be set null or does setting the array = null orphan all its elements?, maybe that will help answer your question.
Following simple code answers the question:
$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