Currently I’m using the following approach to determine if $userlevel is either 10, 20, or 30.
if ( in_array( $userlevel, array( 10, 20, 30 ) ) ) {
}
Is there a better way to do this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You are already using the “better way”. The alternative would be
Typically you’d write a basic
ifstatement until the number of possible values grows such that the line becomes too long, and then you move them into a collection and usein_array.If you know that
$userlevelwill always be one of those values, you could simply test that it’s between the upper/lower bound, but this won’t be any shorter than the way you’re writing it now.