Php krsort
From w3cyberlearnings
Contents |
PHP function krsort
This function sorts array by the array keys in reverse order.
Syntax krsort
- array: array input
- sorttype (optional):
- SORT_REGULAR (Default- sort the array as it is)
- SORT_NUMERIC (Sort array use numerical order)
- SORT_STRING (Sort array as it is string)
- SORT_LOCALE_STRING (Sort array as string based on local settings)
krsort(array, sorttype);
Example 1
<?php $name_s = array( 'Clair' => 3, 'John' => 1, 'Alex' => 100, 'Blair' => 301 ); krsort($name_s); print_r($name_s); ?>
Output
Array ( [John] => 1 [Clair] => 3 [Blair] => 301 [Alex] => 100 )
Example 2
<?php $name_s = array( 'file1' => 3, 'file3' => 1, 'file100' => 100, 'file10' => 100, 'file11' => 300, 'file9' => 301 ); krsort($name_s, SORT_NUMERIC); print_r($name_s); ?>
Output
Array ( [file11] => 300 [file9] => 301 [file10] => 100 [file100] => 100 [file3] => 1 [file1] => 3 )
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