在不规则的序列中使用php模数捕获迭代 [英] Catching iterations using php modulus in an irregular sequence

查看:76
本文介绍了在不规则的序列中使用php模数捕获迭代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何编写一个模数,该模数将依次选择以下迭代?

How can I write a modulus that will select the following iterations in sequence?

1、4、5、8、9、12、13等(+ 3 + 1r)

1, 4, 5, 8, 9, 12, 13 etc (+3+1r)

我正在循环工作并计算帖子(迭代次数).

I'm working within a loop and counting posts (iterations).

例如,我可以通过以下方式捕获每三个帖子(1、4、7、10):-

So for example, I could catch every third post (1, 4, 7, 10) by:-

if ($i % 3 == 1) { echo 'something here'; } 

但是我怎么写一个能抓住1、4、5、8、9、12、13的东西呢?

But how can I write one that will catch 1, 4, 5, 8, 9, 12, 13?

推荐答案

我不太确定您的算法,但是似乎您尝试获取的不是第3和第4个帖子(从0开始).合适的代码为:

I'm not quite sure about your algorithm, but it seems like you try to get every 3rd and 4th post not (starting at 0). The fitting code would be:

if(($i % 4 == 0 || $i % 4 == 1) && $i != 0) { /* do stuff */ }

这篇关于在不规则的序列中使用php模数捕获迭代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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