Jeffro Posted June 12, 2011 Share Posted June 12, 2011 I can't seem to find this with a Google search because it's hard to find relevant info on a search where the primary topic is "or"... so I apologize for what is probably a pretty simple and easy question, but here goes... Is there a really easy way to code, If ($variable = "condition1" or "condition2" or "condition3" or "condition4" or "condition5") { do this; } ....or does this have to be written out as an If else? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/239132-quick-easy-question-on-syntax/ Share on other sites More sharing options...
Alex Posted June 12, 2011 Share Posted June 12, 2011 Well, first off you'd need to use the comparison operator, == (not =). Unfortunately you can't do exactly what you're proposing in PHP, you would have to do: if($var == 'something' || $var == 'something else' || ..) If you have a lot of possible values, alternatively, you could put them in an array and use in_array: $possible_values = array('something', 'something else', 'something else else'); if(in_array($var, $possible_values)) { // ... } Quote Link to comment https://forums.phpfreaks.com/topic/239132-quick-easy-question-on-syntax/#findComment-1228632 Share on other sites More sharing options...
Jeffro Posted June 12, 2011 Author Share Posted June 12, 2011 Exactly what I needed. Big help. Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/239132-quick-easy-question-on-syntax/#findComment-1228639 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.