php check for duplicate values code example
Example 1: check duplicate data in array php
$counts = array_count_values($array);
$duplicate_title = array_filter($array, function ($value) use ($counts) {
return $counts[$value] > 1;
});
Example 2: php get keys of duplicate values in array
<?php
$array = array('a', 'a', 'b', 'c', 'd');
$unique = array_unique($array);
$duplicates = array_diff_assoc($array, $unique);
$result = array_diff($unique, $duplicates);
$unique_keys = array_keys($result);
$duplicate_keys = array_keys(array_intersect($array, $duplicates));