PHPksort () function PHP ksort () function
PHP Array functions
Definition and usage
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.
Syntax
ksort(array,sorttype)
Parameter description
| Array |
Required. Specifies the array to be sorted. |
| Sorttype |
Optional. Specifies how to arrange the values of an array. Possible values: SORT_REGULAR-default. Process with their original type (without changing the type ). SORT_NUMERIC-use the value as a number to process SORT_STRING-use the value as a string to process SORT_LOCALE_STRING-use the value as a string and set it locally *. |
*: 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.
Example
"Dog", "b" => "Cat", "c" => "Horse");ksort($my_array);print_r($my_array);?>
Output:
Array([a] => Dog[b] => Cat[c] => Horse)