Home > Article > Backend Development > What does rsort in php mean?
rsort in php is a function used to sort array cells from high to low. Its usage syntax is such as "rsort(array,sortingtype);". If it succeeds, it returns TRUE, if it fails, Return FALSE.
The operating environment of this article: Windows7 system, PHP7.1 version, DELL G3 computer
What does rsort in php mean?
Instance usage of rsort function in php
After talking about the ascending array method, the corresponding descending method will appear. Before we officially reveal the method, everyone has already learned how to use the sort function, so the corresponding descending function name is rsort(). The two functions are very similar in structure and syntax. Below we will introduce the concept, syntax, return value, and descending order examples of the rsort() function. The specific usage is as follows.
rsort() function behaves opposite to sort(), sorting array cells from high to low.
Note:
If the array elements are numbers, they are sorted according to numbers; if the array elements are strings, they are sorted according to letters; if the array contains numeric values and text/strings, they are sorted according to Alphabetically.
rsort(array,sortingtype);
Returns TRUE if successful and FALSE if failed.
<?php $fruits = array("lemon", "orange", "banana", "apple"); rsort($fruits); foreach ($fruits as $key => $val) { echo "$key = $val "; } ?>
The above will output:
0 = orange
#1 = lemon
2 = banana
3 = apple
fruits are sorted in reverse alphabetical order.
Extension of grammar knowledge points:
Parameters | Description |
---|---|
array | Required. Specifies the array to be sorted. |
sortingtype | Optional. Specifies how the elements/items of an array are arranged. Possible values:
|
Recommended study: "PHP Video Tutorial"
The above is the detailed content of What does rsort in php mean?. For more information, please follow other related articles on the PHP Chinese website!