Array_unique不从正则表达式中排序


array_unique not sorting values from regular expression

所以我有以下正则表达式,我计算匹配的出现次数,如下所示:

preg_match_all("/".$toArray."/i", $input, $matches);
$count_matches = count($matches[0]);

但是,我只想获得那些唯一的匹配。并且将array_unique()应用于以下内容似乎不起作用。

$count_matches = count(array_unique($matches[0]));

[0]会把它弄乱吗?如果是这样,我怎么绕过这个?

似乎您正在尝试计数数组位置

$count_matches = count($matches[0]);

尝试对数组$matches中的位置0进行计数。$matches.

不计算整个数组中有多少个位置