Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End PHP array help Reply To: PHP array help

#170535
__
Participant

When you want to make sure you do something with every element of an array, use foreach.

<?php

foreach( $array as $item ){
    /*  do something to each item in array  */
}

e.g.,

<?php

$LIs = "";
foreach( $yourArray as $item ){
    $LIs .= <<< HTML
<li>
    <a href="{$item['href']}">
        <img src="{$item['img']}">
        {$item['name']}
    </a>
</li>
HTML;
}
print "<ul>$LIs</ul>";