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):

<?php
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
1000

Comments

No comments yet. Be the first!

Most Viewed Articles (in PHP )

Function to convert strings to strict booleans in PHP

All possible substrings in a String in PHP

break out of an if() block in PHP

Exception in module wampmanager.exe at 000F15A0 in Windows 8

History and origin of PHP

PHP ./configure RESULTING IN __rcp_thread_destroy@GLIBC_2_2_3_... AND UNRESOLVED REFERENCES WITH ORACLE OCI8

Convert a hex string into a 32-bit IEEE 754 float number in PHP

PHP Warning: Unknown(): Unable to load dynamic library '/usr/local/php4/lib/php/extensions/no-debug ......

Installing PHP with Apache 2.x on HP UX 11i and configuring PHP with Oracle 9i

Cannot load /usr/local/apache/libexec/libphp4.so into server: ld.so.1:......

Function to return number of digits of an integer in PHP

Perl's Encoding::FixLatin equivalent in PHP

use() in PHP

How to make one else for two ifs in PHP

PHP convert string to lower case

Latest Articles (in PHP)