Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
$values = array('a', 'a', 'b', 'c', 'c');
$result = array_keys(array_filter(array_count_values($values), function($v){
return $v > 1;
}));
print_r($values);
print_r($result);
Array
(
[0] => a
[1] => a
[2] => b
[3] => c
[4] => c
)
Array
(
[0] => a
[1] => c
)
First example here: php.net/manual/ru/function.array-count-values.php
Example #1 Example using array_count_values()
<?php
$array = array(1, "hello", 1, "world", "hello");
print_r(array_count_values($array));
?>
Array
(
[1] => 2
[hello] => 2
[world] => 1
)
<?php
$array = array(1, "hello", 1, "world", "hello");
$array_count = array_count_values($array);
$duplicates = [];
foreach ($array_count as $k=>$v){
if ($v > 1) $duplicates[] = $k;
}
print_r($duplicates);
?>
Perhaps it will help you:
function array_duplicates($arr)
{
$arrUnique = array_unique(array_map("strtoupper", $arr));
$duplicates = array_diff($arr, $arrUnique);
return $duplicates;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question