Last Update : 2023-09-22 UTC 10:24:41 AM
I want to output only duplicate names., w3coded elements find w3coded elements find Stack Overflow w3coded elements find Public questions & answers w3coded elements find , w3coded elements find Stack Overflow for w3coded elements find Teams Where w3coded elements find developers & technologists share private w3coded elements find knowledge with coworkers w3coded elements find , w3coded elements find w3coded elements find Stack Overflow w3coded elements find help chat w3coded elements find
Use this code:
# assuming your original array is $arr
array_unique(array_diff_assoc($arr, array_unique($arr)));
It will return unique duplicates but if you want non-unique duplicates then use:
array_diff_assoc($arr, array_unique($arr));
$uarr = array_unique($arr);
var_dump(array_diff($arr, array_diff($uarr, array_diff_assoc($arr, $uarr))));
array(4) {
[5]=>
string(5) "Ahmed"
[6]=>
string(5) "Ahmed"
[7]=>
string(4) "Ajay"
[8]=>
string(4) "Ajay"
}
Using array_count_values()
to count up everything in the array, then filter the resulting array to show only the ones where there's more than 1:
$input = array(.... your names here ....);
$counts = array_count_values($input);
$duplicates = array_filter($counts, function element { return ($element > 1) });
Last Update : 2023-09-22 UTC 12:23:07 PM
Last Update : 2023-09-22 UTC 12:22:55 PM
Last Update : 2023-09-22 UTC 12:22:47 PM
Last Update : 2023-09-22 UTC 12:22:37 PM
Last Update : 2023-09-22 UTC 12:22:22 PM
Last Update : 2023-09-22 UTC 12:21:28 PM
Last Update : 2023-09-22 UTC 12:21:20 PM