vipsa Posted January 8, 2013 Share Posted January 8, 2013 I am a complete beginner so I need help. I have the following code: <code> $foodprices = array("vegetables"=>array("Tomatoes"=>1.00, "Beet"=>20.5, "Onions"=>3.5), "Meat"=>array("Skaap"=>20.5, "Bees"=>30.5)); var_dump($foodprices); foreach($foodprices as $category) { echo "The current category is $category";//print the category foreach($category as $food => $price) { echo "<br>The price of {$food} is {$price}";//print each item and its price } } </code> I would like to print the category names as well so how do I print the key values of a multidimensional array please. Any help is appreciated Link to comment https://forums.phpfreaks.com/topic/272843-multidimensional-array-foreach-loop/ Share on other sites More sharing options...
Muddy_Funster Posted January 8, 2013 Share Posted January 8, 2013 You are printing the category.... echo "The current category is $category";//print the category Link to comment https://forums.phpfreaks.com/topic/272843-multidimensional-array-foreach-loop/#findComment-1404157 Share on other sites More sharing options...
haku Posted January 8, 2013 Share Posted January 8, 2013 You are already printing the category name. Since you seem to want something else, give us an example of the output you are trying to achieve. Link to comment https://forums.phpfreaks.com/topic/272843-multidimensional-array-foreach-loop/#findComment-1404158 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.