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
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.