I found myself needing to find the first position of multiple needles in one haystack. So I wrote this little function:
<?php
function multineedle_stripos($haystack, $needles, $offset=0) {
foreach($needles as $needle) {
$found[$needle] = stripos($haystack, $needle, $offset);
}
return $found;
}
// It works as such:
$haystack = "The quick brown fox jumps over the lazy dog.";
$needle = array("fox", "dog", ".", "duck")
var_dump(multineedle_stripos($haystack, $needle));
/* Output:
array(3) {
["fox"]=>
int(16)
["dog"]=>
int(40)
["."]=>
int(43)
["duck"]=>
bool(false)
}
*/
?>