Skip to content

Instantly share code, notes, and snippets.

@MontealegreLuis
Created March 8, 2013 18:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MontealegreLuis/5118639 to your computer and use it in GitHub Desktop.
Save MontealegreLuis/5118639 to your computer and use it in GitHub Desktop.
Finding duplicates in an array
<?php
$array = array('pedro', 'juan', 'paco', 'pedro');
$repeated = array_filter(array_count_values($array), function($count) {
return $count > 1;
});
foreach ($repeated as $key => $value) {
echo "Key '$key' is repeated $value times <br />";
}
@jhuertasedu
Copy link

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment