PHP if is a multiple of an integer

后端 未结 5 1959
遥遥无期
遥遥无期 2021-01-25 08:55

Within a for loop, i need to add some HTML that outputs only when the loop is on a [(multiple of 3) minus 1].

For example, what i could do is:

for($i=0;          


        
5条回答
  •  执念已碎
    2021-01-25 09:16

    if ( $i==0 || ($i+1)%3 == 0 )
    {
        //do stuff
    }
    

    What this will do, is go to the next index, divide it by 3, and see if there is a remainder. If there is none, then that means that the current index is one less than a number that is divisible by 3

提交回复
热议问题