私は干し草の山の中のすべての針の位置を見つけようとしています:
$haystack = 'one twoo two one postpone twool';
$needles = array('one', 'two', 'three');
foreach ($needles as $needle) {
if (stristr($haystack, $needle)) { // list position of all needles
$pos[strpos($haystack, $needle)] = $needle;
}
}
print_r($pos);
の値は次の$posとおりです。
Array ( [0] => one [4] => two )
ただし、予想されたのは次のとおりです。
Array ( [0] => one [9] => two [13] => one)
したがって、2つの問題が発生します。
twooの発生としてマークされていますtwo- ループは明らかに2回目の発生と一致しません
one
私は何が間違っているのですか?