<?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"]
More than 5 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme
List of users who liked
46