How to Sort Associative Arrays in Descending Order According to the Key Value in PHP
in this lesson, we will see how to sort associative arrays in descending order according to the key value in PHP, we will use the krsort() function that sorts an associative array in descending order according to the key value.
Sort an associative array in descending order according to the key value
The example below shows how you can Sort an associative array in descending order according to the key value in PHP.
$notes = array("jack" => 12, "adam" => 15, "sam" => 4);
//sort associative array in descending order according to the key value
krsort($notes);
print_r($notes);
//Array ( [sam] => 4 [jack] => 12 [adam] => 15 )