Entry
How can I clear the contents of an array?
Why does my array in a loop contain data from previous loops?
Jul 8th, 1999 21:36
Nathan Wallace, D. Dante Lorenso, Chad Cunningham
You can clear the contents of an array by unsetting it:
http://www.php.net/manual/function.unset.php3
unset($a);
or by resetting it to be an empty array:
$a = array();
You may need to clear the contents of an array when reusing the same
variable to hold different array data (say in a loop). If you don't
clear the contents then the contents from the previous loop iteration
may be left in the array (if the previous array data was longer than the
current array data).