|
Posted by "yanghshiqi" on 07/12/05 20:08
I guess your purpose is to just save the row data from the mysql to the
array each unit. So may be the result that you expected is sth like:
$product[0] = 1;
$product[1] = 2;
$product[2] = 3;
...
If you just "loop for each new value in the loop and to destroy the array",
you second example is okey.
Best regards,
Shiqi Yang
-----Original Message-----
From: Justin Gruenberg [mailto:justin.gruenberg@gmail.com]
Sent: Tuesday, July 12, 2005 7:43 PM
To: virtualsoftware@gmail.com; php-general@lists.php.net
Subject: Re: [PHP] Arrays
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.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Navigation:
[Reply to this message]
|