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