Php rsort
From w3cyberlearnings
Contents |
PHP function rsort
This function sorts array by values in reverse order.
Syntax rsort
- array: array input
- sorttype (optional):
- SORT_REGULAR - (default, don't change type and treat value as it is),
- SORT_NUMERIC - Treat value as numeric
- SORT_STRING - Treat value as string
- SORT_LOCAL_STRING - Treat value based on the local setting.
rsort(array,sorttype);
Note
The rsort function uses quicksort algorithm to reverse sort. Look at sort() function.
Example 1
<?php $score = array(30,20,50,3,5,110,10); print_r($score); rsort($score); print_r($score); ?>
Output
Array ( [0] => 30 [1] => 20 [2] => 50 [3] => 3 [4] => 5 [5] => 110 [6] => 10 ) Array ( [0] => 110 [1] => 50 [2] => 30 [3] => 20 [4] => 10 [5] => 5 [6] => 3 )
Example 2: rsort by string
<?php $score = array(30,20,50,3,5,110,10); print_r($score); rsort($score,SORT_STRING); print_r($score); ?>
Output
Array ( [0] => 30 [1] => 20 [2] => 50 [3] => 3 [4] => 5 [5] => 110 [6] => 10 ) Array ( [0] => 50 [1] => 5 [2] => 30 [3] => 3 [4] => 20 [5] => 110 [6] => 10 )
Related Links
- array_change_key_case
- array_chunk
- array_combine
- array_count_values
- array_diff_assoc
- array_diff_key
- array_diff_uassoc
- array_diff_ukey
- array_diff
- array_fill_keys
- array_fill
- array_filter
- array_flip
- array_intersect_assoc
- array_intersect_key
- array_intersect_uassoc
- array_intersect_ukey
- array_intersect
- array_key_ exists
- array_keys