PHP rsort() Function – Reverse Sorting an Array
The article explains PHP’s rsort() function, which sorts an array in reverse order, details its parameters and return values, and provides a complete example showing how to sort a fruit list and output the sorted elements with their indices.
The PHP rsort() function sorts an array in reverse order, from highest to lowest.
Parameters
array – The input array passed by reference.
sort_flags (optional) – Flags that modify sorting behavior, same as those used by sort() . Default is SORT_REGULAR .
Return value
Returns TRUE on success, or FALSE on failure.
Example
$val) {
echo "$key = $val\n";
}
?>After calling rsort() , the $fruits array is sorted in reverse alphabetical order, and the script outputs:
0 = orange
1 = lemon
2 = banana
3 = appleLaravel Tech Community
Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.