php while loop variable for every third div

后端 未结 4 476
再見小時候
再見小時候 2020-12-10 16:23

Is their a way in a while loop to assign a variable to a class in a div, for every third item in a while loop. I am using the blueprint structure and the third div is at the

4条回答
  •  鱼传尺愫
    2020-12-10 17:18

    If the intention is to do something every X item use modulo. modulo is the remainder of the division and becomes zero if the division is exact an integer.

    if(!($counter%3)) {
        // this is 3 6 9 etc.
    }
    $counter++;
    

    Of course you can do it with any number.

提交回复
热议问题