PHP - Array rsort() Function
The PHP Array rsort() function is used to sort an indexed array in descending order. The function has one optional parameter which can be used to specify sorting type. Please see below for more details.
Syntax
rsort(array, sorting_type)
Parameters
array |
Required. Specify the indexed array to sort |
sorting_type |
Optional. There are six sorting types which are mentioned below:
Note: The | (bitwise operator) can be used to specify more than one sorting type, for example - 4|5. |
Return Value
Returns TRUE on success and False in failure.
Exceptions
NA.
Example:
In the below example, rsort() function is used to sort an indexed array called MyArray in descending order.
<?php $MyArray = array("Marry", "John", "Jo", "Kim", "Adam"); rsort($MyArray); print_r($MyArray); ?>
The output of the above code will be:
Array ( [0] => Marry [1] => Kim [2] => John [3] => Jo [4] => Adam )
❮ PHP Array functions