English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Basic PHP Tutorial

Advanced PHP Tutorial

PHP & MySQL

PHP Reference Manual

PHP rsort() Function Usage and Example

PHP Array Function Manual

The rsort() function sorts an array in reverse order (from highest to lowest).

Syntax

rsort(array $array[, int $sort_flags]);

Definition and Usage

This function sorts the array in reverse order (from highest to lowest).

Parameter

Serial NumberParameters and Description
1

array(Required)

It specifies an array.

2

sort_flags(Optional)

It specifies how to sort the array values. Possible values-

  • SORT_REGULAR - Default value. Treats the value as is (do not change the type)

  • SORT_NUMERIC - Treats the value numerically

  • SORT_STRING - Treats the value as a string

  • SORT_LOCALE_STRING - Treats the value as a string based on local settings

Return Value

Returns TRUE on success, FALSE on failure.

Online Example

 The array input is sorted in reverse alphabetical order.

<?php
   $input = array("d"=>"lemon", "a"=>"orange", "b"=>"banana");
   rsort($input);
   print_r($input);
?>
Test and See‹/›

Output Result

Array ( [0] => orange [1] => lemon [2] => banana )

   PHP Array Function Manual