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

PHP Basic Tutorial

PHP Advanced 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 descriptions
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. Treat the value as is (do not change the type)

  • SORT_NUMERIC - Handle the value numerically

  • SORT_STRING - Treat the value as a string

  • SORT_LOCALE_STRING - Treat the value as a string according to the 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 see if‹/›

Output result

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

   PHP Array Function Manual