English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The ksort() function sorts the array by key name
ksort ( $array, $sort_flag );
The ksort() function sorts the array by key while preserving the association between key names and data. This function is mainly used for associative arrays.
Serial Number | Parameters and Description |
---|---|
1 | array Required. Specify an array |
2 | sort_flag Optional. Specify how to sort the array values. Possible values-
|
This function returns TRUE on success and FALSE on failure.
<?php $transport = array( 'a'=>'foot', 'b'=>'bike', 'c'=>'car', 'd'=>'plane'); ksort($transport); print_r($transport); ?>Test and see‹/›
Output Result:
Array ( [a] => foot [b] => bike [c] => car [d] => plane )