Add a Class to first element in foreach loop

<ul> <? $i = 0; ?> <? foreach($something as $orother): ?> <li <? if($i === 0): ?>class="first"<? endif; ?>> some text </li> <? $i++; ?> <? endforeach; ?> </ul>
This snippet allows you to add a class to the first element with a simple php count

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.