If you are just trying to determine which needles exist in a haystack, I suggest the array_intersect function.
PHP.net Documentation
<?php $array1 = array("a" => "green", "red", "blue"); $array2 = array("b" => "green", "yellow", "red"); $result = array_intersect($array1, $array2); print_r($result); ?> The above example will output: Array ( [a] => green [0] => red )
Basically, this will result in an array that displays all the values ββthat appear in both arrays. In your case, your code returns true if any needle is found. The following code will do this using the array_intersect function, although if this is any simpler than Charles's answer is debatable.
if(sizeof(array_intersect($hackstack, $arrayNeedles)) > 0) return true; else return false;
Again, I'm not sure exactly what your code is trying to do except true if any needle exists. If you can provide some context for what you want to achieve, there may be a better way.
Hope this helps.
source share