[SOLVED] Get multiple values of an Array inside PHP function


This is my code:

function menu_MORE (Array  $ITEMS){
 foreach ($ITEMS as $ITEM) {
  echo "<li><i class='$ITEM[icon]'></i>$ITEM[link]</li>";

$ITEMS = array('link' => array('Edit','Remove'),
               'icon' => array('fa fa-pencil','fa fa-trash'), );


I want the output to be:

<li><i class="fa fa-pencil"></i>Edit</li>
<li><i class="fa fa-trash"></i>Remove</li>

I think i need a second rule/parameter but I can’t figured it out how.

Thank you in advance!


Your array is er… "inverted" — you’re doing this, where each key has multiple values:

$ITEMS = array(
    'link' => array('Edit','Remove'),
    'icon' => array('fa fa-pencil','fa fa-trash')

You want to do this, where you have multiple entries of items, each with a single value:

$ITEMS = array(
        'link' => 'Edit',
        'icon' => 'fa fa-pencil',
        'link' => 'Remove',
        'icon' => 'fa fa-trash',

Answered By – Alex Howansky

Answer Checked By – Jay B. (BugsFixing Admin)

Leave a Reply

Your email address will not be published.