I have a function that takes a string (the haystack) and an array of strings (the needles) and returns true if at least one needle is a substring of the haystack. It didn't take much time or effort to write it, but I'm wondering if there's a PHP function that already does this.
function strstr_array_needle($haystack, $arrayNeedles){
foreach($arrayNeedles as $needle){
if(strstr($haystack, $needle)) return true;
}
return false;
}
just a suggestion...
function array_strpos($haystack, $needles)
{
foreach($needles as $needle)
if(strpos($haystack, $needle) !== false) return true;
return false;
}
I think the closest function would be array_walk_recursive(), but that requires a callback. So using it would probably be more complicated than what you already have.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With