vincej Posted October 24, 2011 Share Posted October 24, 2011 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 ! ! Quote Link to comment https://forums.phpfreaks.com/topic/249735-newbie-needs-help-with-multi-dimensional-array/ Share on other sites More sharing options...
requinix Posted October 24, 2011 Share Posted October 24, 2011 You're going one loop too far - $value is the array you want. foreach ($prod_details as $keyOne => $value) { $prodID = $keyOne; $price = $value['price']; $quantity = $value['count']; Quote Link to comment https://forums.phpfreaks.com/topic/249735-newbie-needs-help-with-multi-dimensional-array/#findComment-1281887 Share on other sites More sharing options...
vincej Posted October 24, 2011 Author Share Posted October 24, 2011 Your're brilliant ! Thank you ! Quote Link to comment https://forums.phpfreaks.com/topic/249735-newbie-needs-help-with-multi-dimensional-array/#findComment-1281897 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.