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

JavaScript must be enabled for certain features to work
* Required information
1000

Comments

No comments yet. Be the first!
(追記) (追記ここまで)
(追記) (追記ここまで)

AltStyle によって変換されたページ (->オリジナル) /