Module operator to run the 1st and then every third element

So I need it to run in the first cycle, and then every third cycle

if ($k % 3 || $k==1 ) { echo '<div class="modcontainer">'; } 

It seems simple to me, but I have no understanding of the module

+5
source share
1 answer

The module returns the remainder, not a boolean.

This code will allow truefor1, 3, 6, 9, ...

if (($k % 3 == 0) || $k==1 ) { echo '<div class="modcontainer">'; } 

This code will allow truefor1, 4, 7, 10, ...

if ($k % 3 == 1) { echo '<div class="modcontainer">'; } 
+9
source

All Articles