Php 中断然后继续循环
如果标题为空,我需要中断循环,然后继续循环数组 像这样的Php 中断然后继续循环,php,Php,如果标题为空,我需要中断循环,然后继续循环数组 像这样的 for($i=0;$i<count($out[0]);$i++){ $title = "$z->extract('<title>','</title>',$data);" if (empty($title)) { break; // Don't continue the sentences below and continuw the next value from the lo
for($i=0;$i<count($out[0]);$i++){
$title = "$z->extract('<title>','</title>',$data);"
if (empty($title)) {
break; // Don't continue the sentences below and continuw the next value from the loop
}
//more sentences php
//more sentences php
//more sentences php
//more sentences php
}
用于($i=0;$i使用
而不是中断;您使用继续;
而不是中断;
来继续下一个循环,而不处理更多的行。您只需将中断
替换为继续您有两个选择:
if (empty($title)) {
$i++;
}
或
<强>解释:考虑循环是< /强>
while {
foreach {
if($i == 2) {
continue 1; //means going to foreach and continue the loop
continue 2; //means going to while and continue the loop
}
}
}
$i=0;$i的
if(!empty($title)){
//more sentences php
//more sentences php
//more sentences php
}
while {
foreach {
if($i == 2) {
continue 1; //means going to foreach and continue the loop
continue 2; //means going to while and continue the loop
}
}
}
for($i=0;$i<count($out[0]);$i++){
$title = "$z->extract('<title>','</title>',$data);"
if (empty($title)) continue;
//more sentences php
//more sentences php
}