Sorting an Associative Array by Value in PHP


Use asort() to sort an array and maintain index association.

Source Code

$fruits = ['d' => 'lemon', 'a' => 'orange', 'b' => 'banana', 'c' => 'apple'];
asort($fruits);
print_r($fruits);
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments