kevin7 Posted October 1, 2009 Share Posted October 1, 2009 I'm suck at foreach with multidimension array, I have this array structure: $item = array( 'chicken' => array('description' => 'a chick', 'quantity' => '5kg'), 'tomatoes' => array('description' => 'a tomato', 'quantity' => '0.5kg') ); and I will the output looks like this, it list out the item name only in a ul list - chicken - tomatoes this is the code i was using, it display "array" foreach ($item as $value => $key) { echo '<li><a href="#">' . $item[$value] . '</a></li>'; } } hmm, what went wrong? Thanks heaps Link to comment https://forums.phpfreaks.com/topic/176127-solved-foreach-question/ Share on other sites More sharing options...
Alex Posted October 1, 2009 Share Posted October 1, 2009 Try this: foreach($item as $key => $val) { echo '<li><a href="#">' . $key . '</a></li>'; } You're misunderstanding the functionality of the foreach. I suggest checking out the manual Link to comment https://forums.phpfreaks.com/topic/176127-solved-foreach-question/#findComment-928075 Share on other sites More sharing options...
kevin7 Posted October 1, 2009 Author Share Posted October 1, 2009 oh man, u r good.. thanks! Link to comment https://forums.phpfreaks.com/topic/176127-solved-foreach-question/#findComment-928079 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.