Php tutorial ksort array key name ranking
The ksort () function sorts the array by key name and retains the original key for the array value.
The second optional parameter contains an additional sorting flag.
If yes, TRUE is returned. Otherwise, FALSE is returned.
This value is newly added to PHP 4.4.0 and 5.0.2. Before PHP 6, you can use setlocale () to change the region settings of the system. From PHP 6, you must use the i18n_loc_set_default () function.
Bool ksort (array & $ array [, int $ sort_flags = SORT_REGULAR])
Let's look at a ksort instance.
<? Php
$ Fruits = array ("d" => "lemon", "a" => "orange", "B" => "banana ", "c" => "apple ");
Ksort ($ fruits );
Foreach ($ fruits as $ key => $ val ){
Echo "$ key = $ valn ";
}
?>
Output duty
A = orange
B = banana
C = apple
D = lemon
Example
<? Php
$ My_array = array ("a" => "www. bKjia. c0m", "B" => "Cat", "c" => "Horse ");
Ksort ($ my_array );
Print_r ($ my_array );
?> Output:
Array
(
[A] => www. bKjia. c0m
[B] => Cat
[C] => Horse
)