文字列と値の配列があります。配列内のアイテムが文字列内に何回表示されるかを確認したいと思います。
これはこれを行うための最速の方法ですか?
$appearsCount = 0;
$string = "This is a string of text containing random abc def";
$items = array("abc", "def", "ghi", "etc");
foreach($items as $item)
{
$appearsCount += substr_count($string, $item);
}
echo "The item appears $appearsCount times";