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 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 ?> 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 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. 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
Archived
This topic is now archived and is closed to further replies.