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? Quote Link to comment 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 Quote Link to comment 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... Quote Link to comment 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. Quote Link to comment 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.