ifubad Posted October 3, 2008 Share Posted October 3, 2008 $a = "b"; if ($a != "b" || $a != "c") { echo "not equal"; } I alway get mixed up on using one or more logical operators with an IF statement $a is equal to "b" and should not echo. But it seems to be executing the second test when it should not. What am I doing wrong? Link to comment https://forums.phpfreaks.com/topic/126937-solved-if-and-using-one-or-more-logical-operators/ Share on other sites More sharing options...
kenrbnsn Posted October 3, 2008 Share Posted October 3, 2008 That "if" statement is saying echo "not equal" if $a is not "b" or $a is not "c" That is true, so the echo is being executed. If you don't want it to echo, you want to use the "&&" operator <?php $a = "b"; if ($a != "b" && $a != "c") { echo "not equal"; }?> Ken Link to comment https://forums.phpfreaks.com/topic/126937-solved-if-and-using-one-or-more-logical-operators/#findComment-656590 Share on other sites More sharing options...
Flames Posted October 3, 2008 Share Posted October 3, 2008 That code seems pointless though as far as i can see it will never occur $a can never be b and c at the same time... Link to comment https://forums.phpfreaks.com/topic/126937-solved-if-and-using-one-or-more-logical-operators/#findComment-656636 Share on other sites More sharing options...
jordanwb Posted October 3, 2008 Share Posted October 3, 2008 That code seems pointless though as far as i can see it will never occur $a can never be b and c at the same time... Unless Erwin Schrödinger's got a hold of it. Link to comment https://forums.phpfreaks.com/topic/126937-solved-if-and-using-one-or-more-logical-operators/#findComment-656672 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.