问题
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
回答1:
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">'; }
来源:https://stackoverflow.com/questions/11261192/modulus-operator-to-run-1st-and-then-every-3rd-item