multiple value check in array php code example
Example 1: php check if any of multiple values in array
function in_array_any($needles, $haystack) {
return !empty(array_intersect($needles, $haystack));
}
echo in_array_any( [3,9], [5,8,3,1,2] );
echo in_array_any( [4,9], [5,8,3,1,2] );
Example 2: in array php multiple values
$haystack = array(...);
$target = array('foo', 'bar');
if(count(array_intersect($haystack, $target)) == count($target)){
}
if(count(array_intersect($haystack, $target)) > 0){
}
Example 3: multiple value match in array php
if (in_array('a', $array_under_test) || in_array('b', $array_under_test)) {
}