PHP - exit from IF block
You can't break if statements, only loops like for or while.
If this if is in a function, use 'return'.
In PHP 5.3 you can use goto
if($bla):
$bla = get_bla();
if(empty($bla)) goto end;
do($bla);
endif;
end:
But personally I think that's an ugly solution.
I cant believe no one have post this solution yet (writing it in my PHP style):
if($bla){do{
$bla = get_bla();
if(empty($bla)) break;
do($bla);
}while(false);}
Complexity still O(1)
Why not just turn it around.
if($bla):
$bla = get_bla();
if(!empty($bla)) {
do($bla);
}
endif;
That way it will only run your code if $bla isn't empty.. That's kinda the point with if-statements