In PHP, is there a short way to compare a variable to multiple values? In PHP, is there a short way to compare a variable to multiple values? php php

In PHP, is there a short way to compare a variable to multiple values?


in_array() is what I use

if (in_array($variable, array('one','two','three'))) {


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";        }