Okay, I believe that I can simplify this line of code except I can’t find anything online. Can anyone help me?
if(empty($action) || $action == "a" || $action == "b" || $action == "c") {
}
Thanks!
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 can use
in_array()to search an array of possible values for$action:I keep the
empty()condition separate becauseempty()tests true for a number of things besides the empty string''.If all you care is to test for the empty string, you can include it in
in_array(), and get rid of thatempty():Performantly, I think explicitly including
empty()is a teeny weeny little bit better, due to short-circuiting.