PHP rsort() function

PHP reset() function
PHP shuffle() function

In this article, you will learn how to sort an indexed array in descending order. The rsort() function arranges the elements of an indexed array in descending order.

What is the syntax of the rsort() function in PHP?

rsort(array, sorttype)
ParameterDetails
arrayThe array to sort in descending order – Required
sorttypeOptional. Specifies how to compare the array elements/items. 
SORT_STRING (default) – Compare elements as strings
SORT_REGULAR – Compares normally without changing the type
SORT_NUMERIC – Compare as numeric values
SORT_LOCALE_STRING – Compare as a string according to the current locale
PHP rsort() function

Examples of rsort() function

Example 1. Sort the elements of the array in descending order alphabetically.

<?php
$arr=array("Suzuki","Corolla","Honda");
rsort($arr);
?>

Example 2. Sort the elements of the array in descending order numerically.

<?php
$n=array(5,7,4,6,23,32);
rsort($n);
?>

PHP reset() function
PHP shuffle() function
en English
X
Scroll to Top