2013-04-06 134 views
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 
} 

感謝等。

回答

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

使用

continue; 

,而不是中斷;

2

您使用continue;而不是break;恢復到下一個循環而不處理其他行。

0

更換break你有兩個,選項:

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

if(!empty($title)){ 
//more sentences php 
//more sentences php 
//more sentences php 
} 
-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 
    } 
    } 
}