Jump to content

Newbie Needs Help with Multi dimensional Array


vincej

Recommended Posts

HI - Pulling my hair out ..  I'm trying to extract from a 3 dimensional array the data for insert to MySql. It  is looping correctly however, and it is inserting, however for some reason I am not getting values for price and quantity, just 0.    The array is contained within

 

 $prod_details = ($_SESSION['cart']);

 

if you do a print_r on the the session, you get :

 

Array
(
    [22] => Array
        (
            [name] => Turkey Jumbo Pack 
            [price] => 155.25
            [count] => 1
        )

    [20] => Array
        (
            [name] => Chicken Variety Pack
            [price] => 120.35
            [count] => 1
        )

)

 

 

I am using a nested foreach loop to traverse the array:

 

 $prod_details = ($_SESSION['cart']);

	foreach ($prod_details as $keyOne=> $value){
 $prodID = $keyOne;
   foreach($value as $keytwo=>$row) {
   $price = $keytwo['price'];
   $quantity = $keytwo['count'];
   }

 

But I all I get out of $price and $quantity when I do an insert is 0.

 

What am I doing wrong ?

 

MANY MANY thanks for all your help ! !

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.