1

So I have the following regex and I count the occurrences of matches like so:

preg_match_all("/".$toArray."/i", $input, $matches);

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

However, I want to get only those matches that are unique. And applying array_unique() to the following does not seem to work.

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

Does the key [0] mess it up? If so how can I go round this?

1 Answers1

0

It seems you are trying to count an array location

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

This tries to count position 0 in the array $matches. Instead of counting how many positions are in the entire array $matches.

jjonesdesign
  • 410
  • 2
  • 14