Re: Arrays

From: Date: Tue, 12 Jul 2005 11:43:05 +0000
Subject: Re: Arrays
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-218536@lists.php.net to get a copy of this message
On 12/07/05, virtualsoftware@gmail.com <virtualsoftware@gmail.com> wrote: > Hi, > > How can i destroy an array? > I mean i have a loop and for each new value in the loop i want to destroy the array. Something > like that: > > while($row = mysql_fetch_array($result)) > { > > $product[] = $product_id; > > // some code here > > } > > I've tried this but doesn't work > > while($row = mysql_fetch_array($result)) > { > > $product = array(); > > $product[] = $product_id; > > // some code here > > } To destroy an array? First of all, where does $product_id come from? You gave us no code that gives us that. Second, if you're trying to make an array populated with a feild from each row returned, your first example will work, but not the second. The second example will empty the array, and start a new one (which doesn't make sense to me why you would do that--because in the end, you're only going to have the array with the last row returned). But if you're trying to destroy an array doing either: unset($an_array) or $an_array = array(); will do the job.

« previous php.general (#218536) next »