Ksort () Definition and usage
The Ksort () function sorts the array in ascending order of the key names and retains the original key for the array value.
The optional second parameter contains the additional sort flags.
If successful, returns TRUE, otherwise returns FALSE.
Grammar
Ksort (array,sorttype) parameter description
Array required. Specify the array to sort.
SortType Optional. Specify how to arrange the values of the array. Possible values:
Sort_regular-Default. Processed in their original type (without changing the type).
Sort_numeric-Handle the value as a number
Sort_string-Handle the value as a string
Sort_locale_string-handles values as strings, based on local settings *.
*: This value is a new addition to PHP 4.4.0 and 5.0.2. Before PHP 6, the locale of the system was used and can be changed with setlocale (). From PHP 6, you must use the I18n_loc_set_default () function.
Example
Copy Code code as follows:
<?php
$my _array = Array ("E" => "Dog", "B" => "Cat", "C" => "horse");
Ksort ($my _array);
Print_r ($my _array);
?>
Output:
Array ([b] => Cat [c] => horse [E] => Sog)