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 the relationship between the 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 compare as strings, based on the 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
- PHP | ArrayIterator ksort() Function
- How to get the function name inside a function in PHP ?
- D3.js | d3.set.add() Function
- CSS | url() Function
- D3.js | d3.set.has() Function
- p5.js | nfp() Function
- p5.js | mag() Function
- p5.js | nf() Function
- p5.js | nfc() function
- PHP | Ds\Set add() Function
- D3.js | d3.map.has() Function
- D3.js | d3.map.get() Function
- p5.js | value() Function
- PHP | Ds\Set last() Function
- PHP | Ds\Set contains() 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 firstname.lastname@example.org. 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.
Improved By : Akanksha_Rai