dreamwest Posted June 5, 2009 Share Posted June 5, 2009 I have no idea whats happening here $action2 ="on"; echo $action2; // this echos on if ($action2 != "off" || $action2 != "on"){ $action2 = "off"; } echo $action2; // this echos off So this echos "on" "off" But the if statement says - if not off or on, set $action2 to off Link to comment https://forums.phpfreaks.com/topic/161047-weird-php/ Share on other sites More sharing options...
Alex Posted June 5, 2009 Share Posted June 5, 2009 It says 'if it doesn't equal on or it doesn't equal off'. So it will always run. Link to comment https://forums.phpfreaks.com/topic/161047-weird-php/#findComment-849886 Share on other sites More sharing options...
dreamwest Posted June 5, 2009 Author Share Posted June 5, 2009 But $action2 does equal to "on", so the if statement shouldnt run Link to comment https://forums.phpfreaks.com/topic/161047-weird-php/#findComment-849896 Share on other sites More sharing options...
Mark Baker Posted June 5, 2009 Share Posted June 5, 2009 You're confusing OR (||) with AND (&&) if ($action2 != "off" || $action2 != "on"){ $action2 != "off" -> True $action2 != "on" -> False OR (||) means if either condition is true, execute the code so because $action2 != "off" is True, the code is executed. if ($action2 != "off" && $action2 != "on"){ $action2 != "off" -> True $action2 != "on" -> False AND (&&) means if both conditions are true, execute the code so because $action2 != "on" is False, the code is not executed. Link to comment https://forums.phpfreaks.com/topic/161047-weird-php/#findComment-849901 Share on other sites More sharing options...
dreamwest Posted June 5, 2009 Author Share Posted June 5, 2009 OK. I see it now, Thanks Link to comment https://forums.phpfreaks.com/topic/161047-weird-php/#findComment-849909 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.