Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: If a equals b or c or d [duplicate]

Possible Duplicate:
Short hand to do something like: if($variable == 1 || $variable == “whatever” || $variable == '492') .

Is this

if ($a==b||$a==c||$a==$d){ ... 

the shortest way to describe this logic. I am thinking about something like

if ($a==($b||$c||$d)) { ...

but that is not a valid code. Any suggestions?

like image 319
Martin Avatar asked Jul 23 '12 11:07

Martin


1 Answers

You could use in_array:

if( in_array($a, array($b,$c,$d)) ){
    //do something
}
like image 58
Engineer Avatar answered Oct 05 '22 17:10

Engineer