然后中断然后继续循环

时间:2013-04-06 19:41:12

标签: 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 loop
   }
//more sentences php
//more sentences php
//more sentences php
//more sentences php
}

感谢。

6 个答案:

答案 0 :(得分:2)

您使用continue;代替break;来恢复到下一个循环而不处理更多行。

答案 1 :(得分:1)

使用

continue;

而不是休息;

答案 2 :(得分:0)

您只需将break替换为continue

即可

答案 3 :(得分:0)

您有两种选择:

if (empty($title)) {
      $i++;
}

if(!empty($title)){
//more sentences php
//more sentences php
//more sentences php
}

答案 4 :(得分:0)

for($i=0;$i<count($out[0]);$i++){

$title = "$z->extract('<title>','</title>',$data);"

if (empty($title)) continue;
 //more sentences php
 //more sentences php 
}

答案 5 :(得分:-1)

解释:考虑循环

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
     }
   }
}