Skip to content
Advertisement

Get the first element in a for loop with php [closed]

How can i add the active class only, just to the first element in this for loop?

JavaScript

I tryed to check it, with the $i == 1 code, but it will add the active class to all the elemtnts.

Advertisement

Answer

Something like that should works. First element is $i == 0 and I used ternary operator to replace if/else is little more elegant

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement