If you are just trying to determine which needles exist in the haystack, I suggest the array_intersect
function.
Documentation from the PHP.net website
<?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 shows all values that appear in both arrays. In your case, your code is returning true if any needle is found. The following code will do this using the array_intersect
function, though if this is any simpler than Charles answer is debatable.
if(sizeof(array_intersect($hackstack, $arrayNeedles)) > 0)
return true;
else
return false;
Again, I am not sure exactly what your code is trying to do, other than return true if any needle exists. If you can provide some context on what you want to achieve, there may be a better way.
Hope this helps.
strstr($haystack, $needle)
tostrpos($haystack, $needle) !== false
... – Commentarystrstr()
should not be used to confirm the existence of a substring (for performance reasons, it is always more ideal to usestrpos()
for such an operation). – Laser