6
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.

Dan D.
  • 73,243
  • 15
  • 104
  • 123
Georgi Georgiev
  • 3,854
  • 5
  • 29
  • 39

3 Answers3

4

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!  
Kaii
  • 20,122
  • 3
  • 38
  • 60
Russell Dias
  • 70,980
  • 5
  • 54
  • 71
4
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

Phill Pafford
  • 83,471
  • 91
  • 263
  • 383
0

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

Guillaume Lebourgeois
  • 3,796
  • 1
  • 20
  • 23