How to use in array for multiple values in PHP

1 Answer

0 votes
function in_array_any($needles, $haystack) {
   return !empty(array_intersect($needles, $haystack));
}

echo (in_array_any([4, 8], [5, 7, 2, 8, 1, 6]) ? "true" : "false") . "\n";

echo (in_array_any([4, 8], [5, 7, 2, 9, 1, 6]) ? "true" : "false");




/*
run:


true
false

*/

 



answered Dec 10, 2021 by avibootz
...