In PHP, is there a short way to compare a variable to multiple values?
Without the need of constructing an array:
if (strstr('onetwothree', $variable))//or case-insensitive => stristr
Of course, technically, this will return true if variable is twothr
, so adding "delimiters" might be handy:
if (stristr('one/two/three', $variable))//or comma's or somehting else
$variable = 'one';// ofc you could put the whole list in the in_array() $list = ['one','two','three'];if(in_array($variable,$list)){ echo "yep"; } else { echo "nope"; }