我有一个字符串和一个数值阵列, 我想检查一个数组中的项目有多少倍出现在字符串中 。
这是最快的方法吗?
$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";