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 ! !

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.