模运算符运行第一个,然后运行第三个项目 [英] modulus operator to run 1st and then every 3rd item

查看:71
本文介绍了模运算符运行第一个,然后运行第三个项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我需要它在第一个循环上运行,然后在每个第三个循环上运行

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

推荐答案

模数返回余数,而不是布尔值.

Modulus returns the remainder, not a boolean value.

对于1, 3, 6, 9, ...,此代码将解析为true

This code will resolve to true for 1, 3, 6, 9, ...

if (($k % 3 == 0) || $k==1 ) { echo '<div class="modcontainer">'; } 

对于1, 4, 7, 10, ...,此代码将解析为true

This code will resolve to true for 1, 4, 7, 10, ...

if ($k % 3 == 1) { echo '<div class="modcontainer">'; } 

这篇关于模运算符运行第一个,然后运行第三个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆