Jump to content

[SOLVED] foreach question


kevin7

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

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