knowram Posted December 18, 2006 Share Posted December 18, 2006 given $yes == "something"why will this work.[code]if ($yes != ""){if ($yes != "no"){//do something here}}[/code]but this will not[code]if ($yes != "" or $yes != "no"){//do something here}[/code] Quote Link to comment Share on other sites More sharing options...
trq Posted December 18, 2006 Share Posted December 18, 2006 It does work. Quote Link to comment Share on other sites More sharing options...
knowram Posted December 18, 2006 Author Share Posted December 18, 2006 That is what I would think to. But if $yes == "no" it still runs the code where I have //do something here Quote Link to comment Share on other sites More sharing options...
thepip3r Posted December 18, 2006 Share Posted December 18, 2006 it should work and you can look at [url=http://us2.php.net/manual/en/language.operators.logical.php]php logical operators[/url] to see that you can use "||" in place of "or" and it gets the same result; the only difference is operator precedence. Quote Link to comment Share on other sites More sharing options...
trq Posted December 18, 2006 Share Posted December 18, 2006 [quote]That is what I would think to. But if $yes == "no" it still runs the code where I have //do something here[/quote]Of course, because ($yes != "") evaluates to true. Quote Link to comment Share on other sites More sharing options...
HuggieBear Posted December 18, 2006 Share Posted December 18, 2006 You're getting this result because you're testing for truth by using negativity. In this instance you'd want AND.[code]<?phpif ($yes != "" && $yes != "no"){//do something here}?>[/code]RegardsHuggie 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.