【发布时间】:2011-07-10 07:01:38
【问题描述】:
有一个foreach 循环,如果某个条件变为有效,是否可以停止它?
示例:
<?php
foreach ($foo as $bar) {
if (2+2 === 4) {
// Do something and stop the cycle
}
}
?>
我尝试使用return 和exit,但没有按预期工作,因为我想继续执行剩下的 PHP 脚本。
【问题讨论】:
-
您尝试过使用
continue和/或break吗?