modulus operator to run 1st and then every 3rd item

后端 未结 1 1420
走了就别回头了
走了就别回头了 2021-01-19 02:31

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

if ($k % 3 || $k==1 ) { echo \'
\'; }

Seems

相关标签:
1条回答
  • 2021-01-19 02:35

    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">'; } 
    
    0 讨论(0)
提交回复
热议问题