Re: Object Undefinded index

From: Date: Thu, 30 Oct 2003 04:28:47 +0000
Subject: Re: Object Undefinded index
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-168115@lists.php.net to get a copy of this message
> foreach ($cart as $product_id => $quantity) > { > echo $product_id . "<br>" . $quantity; > } The way you are accessing the array is incorrect. The $items array is a property of the Cart object. Since the Cart object may have many different array properties, the foreach statement above has to be sepcific about which array you want to iterate through. So the correct code would be: foreach ($cart->items as $product_id => $quantity) { echo $product_id . "<br>" . $quantity; }

« previous php.general (#168115) next »