Alex Rivera | Logout

PHP - exit from IF block

Asked 2010-12-28T11:43:01.503
33

How can I exit a if block if a certain condition is met?

I tried using break but it doesn't work:

if($bla): 
  $bla = get_bla();
  if(empty($bla)) break;
  do($bla);
endif;

it says: Fatal error: Cannot break/continue 1 level in...

Edit
Report

1 Answer

48

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.

answered 2010-12-28T11:48:54.733

Your Answer