Programming Tutorials

break out of an if() block in PHP

By: Strata Ranger in PHP Tutorials on 2012-04-04  

Although most programmers are aware of this already, if for whatever reason you need to 'break' out of an if() block (which, unlike switch() is not considered a looping structure) just wrap it in an appropriate looping structure, such as a do-while(false):

do if ($foo)
  // Do something first...

  // Shall we continue with this block, or exit now?
  if ($abort_if_block) break;

  // Continue doing something...

} while (false);

Add Comment

* Required information


No comments yet. Be the first!

Most Viewed Articles (in PHP )

Latest Articles (in PHP)