The ksort() function is an inbuilt function in PHP which is used to sort an array in ascending order according to its key values. It sorts in a way that relation between indices and values is maintained.
bool ksort( $array, $sorting_type )
Parameters: This function accepts two parameters as mentioned above and described below:
- $array: This parameter specifies the array which needs to be sorted. It is a mandatory parameter.
- $sorting_type: This is an optional parameter. There are different sorting types which are discussed below:
- SORT_REGULAR: The value of $sorting_type is SORT_REGULAR then items are compare normally.
- SORT_NUMERIC: The value of $sorting_type is SORT_NUMERIC then items are compared numerically.
- SORT_STRING: The value of $sorting_type is SORT_STRING then items are compared as a string.
- SORT_LOCALE_STRING: The value of $sorting_type is SORT_STRING then items are compares as string, based on current locale.
Return Value: This function returns True on success or False on failure.
Below programs illustrate the ksort() function in PHP.
 = Java  = SQL  = PL/Sql  = End  = Placement  = Photoshop  = Article  = XML  = C++  = Android  = Graphics  = C#  = ASP.Net
[a] = 77 [b] = 66 [d] = 1 [e] = 56 [i] = 3 [m] = 2 [n] = 44 [o] = 55 [q] = -11 [x] = 33 [y] = 22 [z] = 11
- PHP | Ds\Map::ksort() Function
- ArrayObject ksort() Function in PHP
- How to get the function name inside a function in PHP ?
- PHP | Ds\Map get() Function
- D3.js | d3.hcl() Function
- PHP | Ds\Set xor() Function
- PHP | end() Function
- CSS | hsl() Function
- PHP | next() Function
- PHP | each() Function
- D3.js | d3.lab() Function
- PHP | pow( ) Function
- PHP | dir() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.