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 Quote 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 Quote 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! Quote Link to comment https://forums.phpfreaks.com/topic/176127-solved-foreach-question/#findComment-928079 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.