I have a foreach loop and I need to identify the position of the single items. The items are always 9. I use this code. Someone has a more elegant solution?
<?php
foreach( $fruit as $key => $apple );
?>
<li class="<?php if( ($key == 0) || ($key == 3) || ($key == 6) ) echo 'first'; if( ($key == 1) || ($key == 4) || ($key == 7) ) echo 'middle'; if( ($key == 2) || ($key == 5) || ($key == 8) ) echo 'last'; ?>"
//stuff
</li>
<?php endforeach; ?>
As per commented request though PHP is a language I’ve done little more than potter with
% is the remainder from integer division