Created
March 21, 2013 21:24
-
-
Save potato2003/5216927 to your computer and use it in GitHub Desktop.
重複した要素のみを取得する ref: http://qiita.com/items/13fbec7170da5caa46bc
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 = ['A', 'A', 'A', 'B', 'B', 'C', 'D']; | |
function selectDuplicates($array) { | |
$duplicate = array_filter(array_count_values($array), function($v) { | |
return $v > 1; | |
}); | |
return array_keys($duplicate); | |
} | |
selectDuplicates($array); // => ["A", "B"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment