Skip to content

Instantly share code, notes, and snippets.

@potato2003
Created March 21, 2013 21:24
Show Gist options
  • Save potato2003/5216927 to your computer and use it in GitHub Desktop.
Save potato2003/5216927 to your computer and use it in GitHub Desktop.
重複した要素のみを取得する ref: http://qiita.com/items/13fbec7170da5caa46bc
<?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