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 
}