faqts : Computers : Programming : Languages : PHP : kms : General

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

127 of 134 people (95%) answered Yes
Recently 10 of 10 people (100%) answered Yes

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).