rtpmatt Posted January 27, 2008 Share Posted January 27, 2008 I am just wondering what the evaluation order of an if statement in PHP is, and if it stops evaluating if it passes or fails? thanks -matt Quote Link to comment https://forums.phpfreaks.com/topic/88023-solved-if-statement-evaluation-order/ Share on other sites More sharing options...
Barand Posted January 27, 2008 Share Posted January 27, 2008 Left to right. Yes. <?php $a = 1; $b = 2; if ($a || $b/0) echo 'true'; // true (as $a evaluates to true). $a = 0; if ($a || $b/0) echo 'true'; // div by zero error as second bit needs to be evaluated ?> Quote Link to comment https://forums.phpfreaks.com/topic/88023-solved-if-statement-evaluation-order/#findComment-450375 Share on other sites More sharing options...
jordanwb Posted January 27, 2008 Share Posted January 27, 2008 also certain comparitors take precidence over others. See this page: http://www.php.net/manual/en/language.operators.php Quote Link to comment https://forums.phpfreaks.com/topic/88023-solved-if-statement-evaluation-order/#findComment-450516 Share on other sites More sharing options...
rtpmatt Posted January 28, 2008 Author Share Posted January 28, 2008 Great, thank you very much. Quote Link to comment https://forums.phpfreaks.com/topic/88023-solved-if-statement-evaluation-order/#findComment-450852 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.