我发现自己需要在同一个干草堆中找到多个针的位置。所以我写了这个小函数
<?php
function multineedle_stripos($haystack, $needles, $offset=0) {
foreach($needles as $needle) {
$found[$needle] = stripos($haystack, $needle, $offset);
}
return $found;
}
// 它按如下方式工作:
$haystack = "The quick brown fox jumps over the lazy dog.";
$needle = array("fox", "dog", ".", "duck")
var_dump(multineedle_stripos($haystack, $needle));
/* 输出:
array(3) {
["fox"]=>
int(16)
["dog"]=>
int(40)
["."]=>
int(43)
["duck"]=>
bool(false)
}
*/
?>