PHP: How do you determine every Nth iteration of a loop?

后端 未结 8 1374
Happy的楠姐
Happy的楠姐 2020-11-22 13:12

I wanted to echo an image every after 3 post via XML here is my code :



        
8条回答
  •  孤独总比滥情好
    2020-11-22 14:02

    You can also do it without modulus. Just reset your counter when it matches.

    if($counter == 2) { // matches every 3 iterations
       echo 'image-file';
       $counter = 0; 
    }
    

提交回复
热议问题