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. 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)) { // ... } 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! 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
Archived
This topic is now archived and is closed to further replies.