Web >> Development >> PHP >> How to sort an array

asort($array) - sorts an array while maintaining the index association. This function sorts an array such that array indices maintain their correlation with the array elements they are associated with. This is used mainly when sorting associative arrays where the actual element order is significant. Returns TRUE on success or FALSE on failure. Example 1. asort() example <?php $fruits = array("d" => "lemon", "a" => "orange", "b" => "banana", "c" => "apple"); asort($fruits); reset($fruits); while (list($key, $val) = each($fruits)) { echo "$key = $val\n"; } ?> This example would display: c = apple b = banana d = lemon a = orange