ArrayObject ksort() Function in PHP Last Updated : 11 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report The ksort() function of the ArrayObject class in PHP is used to sort the elements of the ArrayObject according to the keys. This function does not affects the association of the keys with the values, it just sorts the entries of the ArrayObject according to the Keys. Syntax: void ksort() Parameters: This function does not accepts any parameters. Return Value: This function does not returns any value. Below programs illustrate the above function: Program 1: php <?php // PHP program to illustrate the // ksort() function $arr = array("b" => "geeks", "c" => "are", "a" => "awesome"); // Create array object $arrObject = new ArrayObject($arr); // Sort the ArrayObject according to keys $arrObject->ksort(); // Print the sorted ArrayObject print_r($arrObject); ?> Output: ArrayObject Object ( [storage:ArrayObject:private] => Array ( [a] => awesome [b] => geeks [c][/c] => are ) ) Program 2: php <?php // PHP program to illustrate the // ksort() function $arr = array("45" => "geeks", "92" => "are", "10" => "awesome"); // Create array object $arrObject = new ArrayObject($arr); // Sort the ArrayObject $arrObject->ksort(); // Print the ArrayObject print_r($arrObject); ?> Output: ArrayObject Object ( [storage:ArrayObject:private] => Array ( [10] => awesome [45] => geeks [92] => are ) ) Reference: https://www.php.net/manual/en/arrayobject.ksort.php Comment More infoAdvertise with us Next Article ArrayObject uasort() Function in PHP G gopaldave Follow Improve Article Tags : Web Technologies PHP PHP-array PHP-function PHP-ArrayObject +1 More Similar Reads ArrayObject natsort() Function in PHP The natsort() function of the ArrayObject class in PHP is used to sort the elements of the ArrayObject following a natural order sorting algorithm. The natsort() function is used to sort alphanumeric strings in a order a normal human being would do. Syntax: void natsort() Parameters: This function d 2 min read ArrayObject natcasesort() Function in PHP The natcasesort() function of the ArrayObject class in PHP is used to sort the elements of the ArrayObject following a natural order case sensitive sorting algorithm. Natural ordering means to arrange the elements in a order a normal human being would do. Syntax: void natcasesort() Parameters: This 2 min read ArrayObject uksort() Function in PHP The uksort() function of the ArrayObject class in PHP is used to sort the entries present in the ArrayObject according to the keys following a user-defined function. They key-value mapping is preserved after sorting the ArrayObject. Syntax: void uksort($comparator) Parameters: This function accepts 2 min read ArrayObject offsetGet() Function in PHP The offsetGet() function of the ArrayObject class in PHP is used to get the value present at a specific index at the ArrayObject. Syntax: mixed offsetGet($index) Parameters: This function accepts a single parameter $index for which corresponding value will be returned. Return Value: This function re 1 min read ArrayObject uasort() Function in PHP The uasort() function of the ArrayObject class in PHP is used to sort values of an ArrayObject according to a user defined comparison function. The function compares and arranges the values present in the ArrayObject according to the given comparison function. This method does not affects the key-va 2 min read ArrayObject asort() Function in PHP The asort() function of the ArrayObject class in PHP is used to sort all of the entries of the ArrayObject according to the values. The elements are arranged according to the values keeping the maintaining the association of the keys with the value. Syntax: void asort() Parameters: This function doe 1 min read Like