如何计算已找到的关键字出现的次数?目前我有这个
$filesfound = false;
foreach ($arr as $file)
$filesfound = true;
...echo $vouchers = ($filesfound === true) && (strpos(implode('/', $file), 'Voucher') !== false) ? '<div>+ 2 Files Available</div>' : '';我试图获得"+2文件可用“,以实际帐户字符串发生的发现。我该怎么做?多个函数没有给出我期望的结果。在这种情况下,我期望2的正确阅读
谢谢!!
溶液
$filesfound = false;
foreach ($arr as $file) {
// If occurrences were found. Returns 0 for each match, so we add + 1
if (strpos(implode('/', $file), 'Voucher') === 0) {
$filesfound = true;
$count = $count + 1;
}
}
echo $count;发布于 2022-01-28 22:11:56
若要计数字符串中出现的文本,可以使用:
$text = 'This is a test';
// find how many "is" are within our $text variable:
echo substr_count($text, 'is'); // this will return 2, since there are 2 of "is" in our $texthttps://stackoverflow.com/questions/70900646
复制相似问题