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
The modulo operator, denoted by %, is an arithmetic operator. The modulo division operator produces the remainder of an integer division.
The modulo operation (abbreviated “mod”, or “%” in many programming languages) is the remainder when dividing. For example, “5 mod 3 = 2” which means 2 is the remainder when you divide 5 by 3.
The modulus operator (also informally known as the remainder operator) is an operator that returns the remainder after doing an integer division. For example, 7 / 4 = 1 remainder 3. Therefore, 7 % 4 = 3. As another example, 25 / 7 = 3 remainder 4, thus 25 % 7 = 4.
The Modulus is the remainder of the euclidean division of one number by another. % is called the modulo operation. For instance, 9 divided by 4 equals 2 but it remains 1 . Here, 9 / 4 = 2 and 9 % 4 = 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">'; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With