Php natcasesort
From w3cyberlearnings
Contents |
PHP function natcasesort
This function sorts array by using the natural order algorithm, and this sorting function is case-insensitive.
Natural order algorithm works this way: 1 is before 2, 500 is before 501.
Syntax natcasesort
- array: array input
natcasesort(array);
Note
For case sensitive natural order sorting uses natsort() function.
Example 1
<?php $tfile = array( 'file01', 'file02', 'file30', 'file1', 'file5', 'File51', 'File30', 'file06' ); natcasesort($tfile); print_r($tfile); ?>
Output
Array ( [0] => file01 [1] => file02 [7] => file06 [3] => file1 [4] => file5 [6] => File30 [2] => file30 [5] => File51 )
Example 2
<?php $name_s = array( 'bob' => 'R302', 'janny' => 'A304', 'mark' => 'A303', 'john'=>'a305', 'mark3'=>'a302' ); natcasesort($name_s); print_r($name_s); ?>
Output
Array ( [mark3] => a302 [mark] => A303 [janny] => A304 [john] => a305 [bob] => R302 )
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