开发者

PHP Fatal error: Cannot break/continue

开发者 https://www.devze.com 2023-01-14 22:12 出处:网络
if (isset($errors)) { foreach ($errors as开发者_如何转开发 $error) { echo $error; } } else {break 2;}
if (isset($errors))  
{  
foreach ($errors as开发者_如何转开发 $error)  
  {  
    echo $error;  
  }    
}  
else {break 2;}  
// some more code

Outputs:

Fatal error: Cannot break/continue 2 levels  

I tried break 1, it didn't work either.


if (isset($errors))  
{  
foreach ($errors as $error)  
  {  
    echo $error;  
  }    
}  

No need to use break as you seem to want to end on the else condition. just use the above code for your errors, it will be skipped if no errors. No need for break


Break ends the execution within a foreach, for, while, do-while or switch structure..

if (isset($errors))  
{  
foreach ($errors as $error)  
  {  
    echo $error;  
  }    
}  
else {break 2;} //there is no loop here!  


Just type break not followed with any number. But break is helpless outside of a loop / block.

0

精彩评论

暂无评论...
验证码 换一张
取 消