ArrayObject uksort() Function in PHP Last Updated : 11 Jul, 2025 Comments Improve Suggest changes Like Article Like Report 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 a single parameter $comparator which is the user defined comparison function. This comparison function in turn accepts two arguments which are the keys of the ArrayObject and returns less than, equals to or greater than zero if the first argument is less than, equals to or greater than zero respectively. Return Value: This function does not returns any value. Below program illustrate the above function: php <?php // PHP program to illustrate the // uksort() function $arr = array("1"=>"Welcome", "2" => "to", "3" => "GfG"); // Create array object $arrObject = new ArrayObject($arr); // Declare a comparison function to sort // the entries by keys in descending order function comparison($val1, $val2) { if ($val1 == $val2) { return 0; } else if($val1 > $val2) return -1; else return 1; } $arrObject->uksort('comparison'); // Print the sorted ArrayObject print_r($arrObject); ?> Output: ArrayObject Object ( [storage:ArrayObject:private] => Array ( [3] => GfG [2] => to [1] => Welcome ) ) Reference: https://www.php.net/manual/en/arrayobject.uksort.php Create Quiz Comment G gopaldave Follow 0 Improve G gopaldave Follow 0 Improve Article Tags : Web Technologies PHP PHP-function PHP-ArrayObject Explore BasicsPHP Syntax4 min readPHP Variables5 min readPHP | Functions6 min readPHP Loops4 min readArrayPHP Arrays5 min readPHP Associative Arrays4 min readMultidimensional arrays in PHP5 min readSorting Arrays in PHP4 min readOOPs & InterfacesPHP Classes2 min readPHP | Constructors and Destructors5 min readPHP Access Modifiers4 min readMultiple Inheritance in PHP4 min readMySQL DatabasePHP | MySQL Database Introduction4 min readPHP Database connection2 min readPHP | MySQL ( Creating Database )3 min readPHP | MySQL ( Creating Table )3 min readPHP AdvancePHP Superglobals6 min readPHP | Regular Expressions12 min readPHP Form Handling4 min readPHP File Handling4 min readPHP | Uploading File3 min readPHP Cookies9 min readPHP | Sessions7 min read Like