简体   繁体   中英

Break then continue the loop

I need to break the loop if the title is empty Then continue the loop array

Something like this

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
}

thanks.

you use continue; instead of break; to resume to the next loop without processing the further lines.

use

continue;

instead of break;

你需要用continue替换break

You have two choises:

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

or

if(!empty($title)){
//more sentences php
//more sentences php
//more sentences php
}
for($i=0;$i<count($out[0]);$i++){

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

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

Explanations: consider the loops are

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM