PHP rsort() Function

PHP rsort Function


Definition :

The rsort() function is used to sorts the values of the indexed array in descending order.

Syntax

   rsort(array, sorttype)

Parameters

The rsort() function accepts the following parameters.

Parameter Description
array Required. Specifies the array to sort.
sort_flags

Optional. Specifies how array items should be compared. Possible values are:

  • SORT_REGULAR – Compare items normally (don't change types). Default value.
  • SORT_NUMERIC – Compare items numerically.
  • SORT_STRING – Compare items as strings.
  • SORT_LOCALE_STRING – Compare items as strings, based on the current locale.
  • SORT_NATURAL – Compare items as strings using natural ordering.
  • SORT_FLAG_CASE – Can be combined (bitwise OR) with SORT_STRING or SORT_NATURAL to sort strings case-insensitively.

Example1 : Given below example Sort the elements of the $webiste array in descending alphabetical order

Output :

Array
(
    [0] => web
    [1] => promotion
    [2] => online
    [3] => house
    [4] => desinging
)

Eample2 : following example sorts an indexed array having numeric values in descending order

Output :

Array
(
    [0] => 20
    [1] => 15
    [2] => 13
    [3] => 5
    [4] => 2
)