Find All Duplicates

Find all elements that appear more than once in an array using frequency counting.

Code

Algorithms
$counts = array_count_values($arr);
$dups = array_keys(array_filter($counts, fn($v) => $v > 1));
return array_values($dups);

Parameters

Array to check

Server

More PHP Snippets