5

So i need it to run on the first loop and then every 3rd loop

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

Seems simple to me, but i don't have the understanding of modulus

Jamie Hutber
  • 26,790
  • 46
  • 179
  • 291

1 Answers1

12

Modulus returns the remainder, not a boolean value.

This code will resolve to true for 1, 3, 6, 9, ...

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

This code will resolve to true for 1, 4, 7, 10, ...

if ($k % 3 == 1) { echo '<div class="modcontainer">'; } 
user247702
  • 23,641
  • 15
  • 110
  • 157