Backend Development 2 min read

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.

Laravel Tech Community
Laravel Tech Community
Laravel Tech Community
PHP rsort() Function – Reverse Sorting an Array

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 = apple
Backend DevelopmentExample Codearray-sortingrsort
Laravel Tech Community
Written by

Laravel Tech Community

Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.