3v4l.org

run code in 300+ PHP versions simultaneously
<?php function countUnique($a) { $acv=array_count_values($a); $n=0; foreach ($acv as $f) if ($f==1) $n++; return $n; } function countUniqueTML($a) { return array_reduce( array_count_values($a), function($c, $i) { return ($i === 1) ? $c + 1 : $c; }, 0); } function countUniqueGG($a) { $cardinal=[]; foreach($a as $v) if (isset($cardinal[$v])) $cardinal[$v] = 0; else $cardinal[$v] = 1; return array_sum($cardinal); } $a=[1,1,2,2,2,5,6]; echo countUniqueTML($a); echo "\n"; echo countUnique($a); echo "\n"; echo countUnique($a);

preferences:
30.61 ms | 406 KiB | 5 Q