Lisa23 Posted July 19, 2010 Share Posted July 19, 2010 is possible to use this expression <?php if($tag=="home || about || contact"):?> basically i what if tag equals home or about or contact is the way i'm trying valid Link to comment https://forums.phpfreaks.com/topic/208133-or-expression-doenst-work/ Share on other sites More sharing options...
Pikachu2000 Posted July 19, 2010 Share Posted July 19, 2010 Not quite like that, but yes you can use it with the correct syntax. <?php if($tag=='home' || $tag=='about' || $tag=='contact') { // DO SOMETHING } else { // DO SOMETHING ELSE } ?> Link to comment https://forums.phpfreaks.com/topic/208133-or-expression-doenst-work/#findComment-1087959 Share on other sites More sharing options...
PFMaBiSmAd Posted July 19, 2010 Share Posted July 19, 2010 No, for at least two reasons. First, you have double-quotes around "home || about || contact". That is checking if $tag is equal to the string 'home || about || contact' Secondly, without the quotes, you would be or'ing home with about and then or'ing that with contact and that as a logic expression is equal to TRUE. So you would be checking if $tag is a TRUE value and that would be true for a lot of different values. Computers don't apply the distributive property to what you write. You must explicitly write out the logic test that you want or find a different method. Since you are testing if something is any one of a list of values, it would be easier to put those values into an array and use the in_array function. Link to comment https://forums.phpfreaks.com/topic/208133-or-expression-doenst-work/#findComment-1087961 Share on other sites More sharing options...
inversesoft123 Posted July 19, 2010 Share Posted July 19, 2010 Also, this code fragment is not a full statement, there is no closing semicolon at all. Link to comment https://forums.phpfreaks.com/topic/208133-or-expression-doenst-work/#findComment-1087964 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.