chantown Posted June 18, 2009 Share Posted June 18, 2009 Instead of doing this: if($action=="1" || $action=="2" || $action=="6" || $action=="99").. Can I do a shortcut? if($action==[2,6,3])) something like this? Quote Link to comment https://forums.phpfreaks.com/topic/162696-i-want-to-check-if-a-variable-equals-many-things/ Share on other sites More sharing options...
Maq Posted June 18, 2009 Share Posted June 18, 2009 You could whitelist the values, and check $action with with in_array. $action = 3; $valid = array(1,2,3,4,5,6,7); if(in_array($action, $valid)) { echo "true"; } Quote Link to comment https://forums.phpfreaks.com/topic/162696-i-want-to-check-if-a-variable-equals-many-things/#findComment-858600 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.