I want to first get the keys with the same values and then keep the keys with the longest string. Here is the code compiled so far:
<?php
$data = array('Anna' => 1, 'Ann' => 1, 'Tommy' => 100, 'Tom' => 100);
$total = array_count_values($data);
$filtered = array_filter($data, function ($value) use ($total) {
return $total[$value] > 1;
});
print_r($filtered);
?>
The current output:
Array ( [Anna] => 1 [Ann] => 1 [Tommy] => 100 [Tom] => 100 )
My expected output:
Array ( [Anna] => 1 [Tommy] => 100)
Many thanks for help.