Syntax: rsort(array &$array, int $flags = SORT_REGULAR): bool. The function returns true on success, false on failure. The array is passed by reference. Basic rsort ExampleThis demonstrates sorting a simple numeric array in descending order. basic_rsort.php ...
PHP rsort() function Thersort()function is used to sort an indexed array in descending order. If array elements are numeric, it sorts based on the numbers, if array elements are the string, it sorts based on the alphabets and if the array contains numeric values and text/strings, it so...
In this article, we show how to sort numbers of an array in descending order in PHP. To sort an array of numbers in descending order in PHP, we use thersort()function. Let's say we have the array of numbers below: $numbers= array(48, 93, 4, 6, 21, 11, 32, 17); A...
$a2=array("Pluto","Fido","Missy"); array_multisort($a1,SORT_ASC,$a2,SORT_DESC); print_r($a1); print_r($a2); ?> Run example » Example 4 Merge two arrays and sort them as numbers, in descending order: <?php $a1=array(1,30,15,7,25); ...
array1_sort_order Optional. Specifies the sorting order. Possible values are: SORT_ASC– Sort in ascending order (A-Z). Default value. SORT_DESC– Sort in descending order (Z-A). array1_sort_flags Optional. Specifies how array items should be compared. Possible values are: ...
sort modes:* - random: random array order* - reverse: last entry will be first, first the last.* - asce: sort array in ascending order.* - desc: sort array in descending order.* - natural: sort with a 'natural order' algorithm. See PHPs natsort() function.** In addition, this ...
SORT_DESC sort in descending order (Z-A) 3 Sorting type(Optional) It specifies the type to use, when comparing elements. Possible values − SORT_REGULAR Default. Compare elements normally SORT_NUMERIC Compare elements as numeric values SORT_STRING Compare elements as string values 4 array2(Opt...
<?php $cars =array("Volvo","BMW","Toyota"); sort($cars); ?> Try it Yourself » Definition and Usage The sort() function sorts an indexed array in ascending order. Tip:Use thersort()function to sort an indexed array in descending order. ...
<?php $a1=array("Dog","Dog","Cat"); $a2=array("Pluto","Fido","Missy"); array_multisort($a1,SORT_ASC,$a2,SORT_DESC); print_r($a1); print_r($a2); ?> Try it Yourself » Example Merge two arrays and sort them as numbers, in descending order: ...
php $names = array("Alice", "Bob", "Charlie", "David"); $scores = array(90, 75, 88, 95); // Sorting by scores in descending order array_multisort($scores, SORT_DESC, $names); print_r($names); print_r($scores); The resulting output will be: ...