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] Link to comment https://forums.phpfreaks.com/topic/31170-solved-stupid-if-statement-question/ Share on other sites More sharing options...
trq Posted December 18, 2006 Share Posted December 18, 2006 It does work. Link to comment https://forums.phpfreaks.com/topic/31170-solved-stupid-if-statement-question/#findComment-144028 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 Link to comment https://forums.phpfreaks.com/topic/31170-solved-stupid-if-statement-question/#findComment-144036 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. Link to comment https://forums.phpfreaks.com/topic/31170-solved-stupid-if-statement-question/#findComment-144040 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. Link to comment https://forums.phpfreaks.com/topic/31170-solved-stupid-if-statement-question/#findComment-144042 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 Link to comment https://forums.phpfreaks.com/topic/31170-solved-stupid-if-statement-question/#findComment-144054 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.