|
Posted by Jason Wong on 01/06/05 11:06
On Thursday 06 January 2005 05:17, Gunter Sammet wrote:
> I am having some trouble getting the following code to work:
>
> if (is_array($bundle_attributes)) {
>
> reset($bundle_attributes);
>
> while (list($option, $value) = each($bundle_attributes)) {
>
> reset($value);
>
> while (list($option2, $value2) = each($value)) {
>
> $this->contents[$products_id]['attributes'][$option] = $value;
>
> if (tep_session_is_registered('customer_id')) tep_db_query("insert into " .
> TABLE_CUSTOMERS_BASKET_BUNDLE_ATTRIBUTES . " (customers_id, products_id,
> sub_product_id, products_options_id, products_options_value_id) values ('"
> . (int)$customer_id . "', '" . tep_db_input($products_id) . "', '" .
> $option . "', '" . (int)$option2 . "', '" . (int)$value2 . "')");
>
> }
>
> }
>
> }
>
> }
>
> It gives me an endless loop in the second while loop. It seems like it
> doesn't move the pointer to the next value in the $option array.
But isn't the "next value" of $option controlled by the outer while-loop?
> When I do
> a print in that loop, I am getting the key value pair for the first element
> in the $option array.
So inside the inner while-loop, $option should never change.
> Changing it to a for loop works. Any ideas why this
> happens?
No. But I can tell you that:
1) the reset() aren't necessary
2) even better, use a foreach-loop instead of while-loop
--
Jason Wong -> Gremlins Associates -> www.gremlins.biz
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *
------------------------------------------
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
------------------------------------------
New Year Resolution: Ignore top posted posts
Navigation:
[Reply to this message]
|