Possible duplicate:Short hand to do something like: if ($ variable == 1 || $ variable == "whatever" || $ variable == '492').
it
if ($a==b||$a==c||$a==$d){ ...
the shortest way to describe this logic. I think of something like
if ($a==($b||$c||$d)) { ...
but this is invalid code. Any suggestions?
You can use in_array :
if( in_array($a, array($b,$c,$d)) ){ //do something }
This is valid code, but not logically correct.
If you have a lot of meanings, you can do something like this.
if(in_array($a,array($b,$c,$d))) { }
This is not the same as being ||a logical operator and will always return trueor false. So, in the second expression, you are comparing if $a- trueor false.
||
true
false
$a
You can use in_arrayto compare if $aexists inarray($b, $c, $d)
in_array
array($b, $c, $d)
I don’t know why you want to do something, but you can put b, c, d in an array and call the in_array function to find the elements. However, I cannot understand why you want the short and simple code to be made short and complicated.