Input Array
$userArr = array("0"=>"Veronica", "1"=>"Alex", "2"=>"Joe", "3"=>"Alex", "4"=>"Veronica");
Here, user Veronica
and Alex
are repeated twice. How do I sort above array reverse alphabetical way even if count of two users are same i.e. Veronica => 2, Alex => 2
, only Veronica
will be displayed as output string.
$userArr = array("0"=>"Veronica", "1"=>"Alex", "2"=>"Joe", "3"=>"Alex", "4"=>"Veronica");
$userCnt = array_count_values($userArr);
foreach ($userCnt as $key => $val) {
echo "$key = $val
";
}
Output:
Veronica