Page 1 of 1

Multidimensional Arrays

Posted: Sun Aug 21, 2011 2:58 pm
by chuck2282
Hi,

I have an array that I'm having trouble with. Below is how Im accessing it and the dump output

Code: Select all

$cart = $_SESSION['cart']->contents;
var_dump($cart);

array(2) { [11880]=> array(1) { ["qty"]=> string(1) "1" } [9132]=> array(1) { ["qty"]=> float(2) } } 
I'm trying to assing 11880 to a product_id and the value of qty to variables. And the same with 9132... How can I loop through this array and store these values?

I don't have much experence with Multidimensional Arrays and any help is much appreciated.

Re: Multidimensional Arrays

Posted: Sun Aug 21, 2011 4:38 pm
by AbraCadaver

Code: Select all

foreach($cart as $key => $value) {
   echo $key . ' ' . $value['qty'];
}