This is a PHP function to sort arrays by keys. Returns either TRUE or FALSE.

ksort() takes in an array as argument and sorts this array by keys/indexes. Since the passed array is taken as pass-by-reference, the original array itself is updated/sorted.

Short Info

Sorts an array by key, maintaining key to data correlations. This is useful mainly for associative arrays. The function returns TRUE on success or FALSE on failure.

Usage

bool ksort ( array &$array [, int $sort_flags = SORT_REGULAR ] )
  • bool is the return value type.
  • array is passed variable type.
  • $sort_flags is optional parameter to modify sorting feature.

More information on the sort_flags is available here.

Miscellaneous

The functionkrsort() can be used to sort an array by key in reverse order.