0

如果标题为空,我需要打破循环然后继续循环数组

像这样的东西

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
}

谢谢。

4

6 回答 6

2

您使用continue;而不是break;恢复到下一个循环而不处理其他行。

于 2013-04-06T19:43:14.990 回答
1

采用

continue;

而不是休息;

于 2013-04-06T19:43:05.457 回答
0

你只需要替换breakcontinue

于 2013-04-06T19:43:26.020 回答
0

你有两个选择:

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

或者

if(!empty($title)){
//more sentences php
//more sentences php
//more sentences php
}
于 2013-04-06T19:45:56.417 回答
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 
}
于 2013-04-06T19:49:59.097 回答
-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
     }
   }
}
于 2013-04-06T19:46:04.120 回答