Which is faster: in_array() or a bunch of expressions in PHP?
- by Darryl Hein
Is it faster to do the following:
if ($var != 'test1' && $var != 'test2' && $var != 'test3' && $var != 'test4') { ... }
Or:
if (!in_array($var, array('test1', 'test2', 'test3', 'test4') { ... }
Is there a number of values at which point it's faster to do one or the other?
(In this case, the array used in the second option doesn't alreay exist.)