更改 foreach 循环中的自动递增量
有没有办法让 foreach 循环增量超过 1?我在 foreach 循环中的每个项目之前加载 jquery 脚本,并且希望每个项目的延迟增加 300,以便每个项目单独动画而不是同时动画。
那么除了$i++还有其他方法吗?比如 $i++ + 300?或者我在这个问题上做得有点过分了?
感谢大家这么快的回复。 $i+=300 正是我正在寻找的。我使用此变量来增加每个脚本的延迟时间,以便在循环中的每个项目上一次执行一个脚本。这是我使用它的用途的链接。再次感谢!
Is there a way to make a foreach loop increment by more than one? I am loading a jquery script before each item in a foreach loop and I want the delay to increase by 300 for each item, so that each item animates separately as opposed to at the same time.
So is there another method other than $i++? Like $i++ + 300? Or I am reaching a little too far on this one?
Thanks everyone for responding so quickly. The $i+=300 was exactly what I was looking for. I used this variable to increase the delay time on each of the scripts so it is executed one at a time on each item in the loop. Here is a link to what I used it for. Thanks again!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
基本上你需要自己看管柜台。
例如:
Basically you need to look after the counter yourself.
For example:
您是否正在寻找这样的东西:
Are you looking for something like this:
你的问题对我来说有点不清楚,但似乎你可以简单地使用
i*300
作为动画间隔(例如foreach ($foo as $i => $bar) {// *在这里简单地使用 $i*300 作为间隔*/ }
)但是,仅供参考,在常规的
for
循环中,您可以使用$i+=300
(例如为($i=0; $i<10000; $i+=300)
在foreach
循环中执行类似的操作没有多大意义。变量来跟踪它并每次增加 300 ($i=0; foreach ($foo as $bar) { ... $i+=300 }
)。Your question is kinda unclear to me, but it seems like you can simply use
i*300
as your animation interval (e.g.foreach ($foo as $i => $bar) { /*simply use $i*300 as your interval here*/ }
)However, just FIY, n a regular
for
loop you can use$i+=300
(e.g.for ($i=0; $i<10000; $i+=300)
. It doesn't make much sense to do anything like that in anforeach
loop. Instead, keep a separate variable to keep track of that and increase that be 300 every time ($i=0; foreach ($foo as $bar) { ... $i+=300 }
).