跳过当前迭代 [英] skip current iteration

查看:74
本文介绍了跳过当前迭代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个php数组$numbers = array(1,2,3,4,5,6,7,8,9)

如果我使用foreach foreach($numbers as $number)

if I am looping over it using a foreach foreach($numbers as $number)

并具有一条if语句if($number == 4)

那之后的代码行将跳过该行之后的任何内容并在5开始循环吗?休息,返回,退出?

what would the line of code be after that that would skip anything after that line and start the loop at 5? break, return, exit?

推荐答案

您正在寻找 continue 语句. break 也很有用,它将完全退出循环.这两个语句都适用于循环的所有变体,即. forforeachwhile.

You are looking for the continue statement. Also useful is break which will exit the loop completely. Both statements work with all variations of loop, ie. for, foreach and while.

$numbers = array( 1, 2, 3, 4, 5, 6, 7, 8, 9 );
foreach( $numbers as $number ) {
    if ( $number == 4 ) { continue; }
    // ... snip
}

这篇关于跳过当前迭代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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