Created
March 8, 2013 18:24
-
-
Save MontealegreLuis/5118639 to your computer and use it in GitHub Desktop.
Finding duplicates in an array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 />"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks