PHP | ArrayIterator uksort() Function Last Updated : 21 Nov, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report The ArrayIterator::uksort() function is an inbuilt function in PHP which is used to sort the keys by using a user-defined comparison function. Syntax: void ArrayIterator::uksort( callable $cmp_function ) Parameters: This function accepts single parameter $cmp_function which holds the user defined comparison function. Return Value: This function does not return any value. Below programs illustrate the ArrayIterator::uksort() function in PHP: Program 1: php <?php // Declare an ArrayIterator $arrItr = new ArrayIterator( array( "a" => 4, "b" => 2, "g" => 8, "d" => 6, "e" => 1, "f" => 9 ) ); // User defined comparator function function sorting($a, $b) { if($a == $b) return 0; return ($a < $b) ? -1 : 1; } $arrItr->uksort("sorting"); // Printing the sorted array. print_r($arrItr); ?> Output: ArrayIterator Object ( [storage:ArrayIterator:private] => Array ( [a] => 4 [b] => 2 [d] => 6 [e] => 1 [f] => 9 [g] => 8 ) ) Program 2: php <?php // Declare an ArrayIterator $arrItr = new ArrayIterator( array( "b" => "for", "a" => "Geeks", "e" => "Science", "c" => "Geeks", "f" => "Portal", "d" => "Computer" ) ); // Declare a comparison function to sort // values in descending order function comparison($val1, $val2) { if ($val1 == $val2) { return 0; } else if($val1 > $val2) return -1; else return 1; } $arrItr->uksort('comparison'); // Print the sorted ArrayObject print_r($arrItr); ?> Output: ArrayIterator Object ( [storage:ArrayIterator:private] => Array ( [f] => Portal [e] => Science [d] => Computer [c][/c] => Geeks [b] => for [a] => Geeks ) ) Reference: https://www.php.net/manual/en/arrayiterator.uksort.php Comment More infoAdvertise with us Next Article PHP | ArrayIterator seek() Function J jit_t Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-Iterators PHP-ArrayIterator +1 More Similar Reads PHP | ArrayIterator uasort() Function The ArrayIterator::uasort() function is an inbuilt function in PHP which is used to sort the element using a user-defined comparison function and maintain their index association. Syntax: void ArrayIterator::uasort( callable $cmp_function ) Parameters: This function accepts a single parameter $cmp_f 2 min read PHP | ArrayIterator seek() Function The ArrayIterator::seek() function is an inbuilt function in PHP which is used to seek the position of an array iterator. Syntax: void ArrayIterator::seek( int $position ) Parameters: This function accepts single parameter $position which holds the position to seek. Return Value: This function does 1 min read PHP | ArrayIterator seek() Function The ArrayIterator::seek() function is an inbuilt function in PHP which is used to seek the position of an array iterator. Syntax: void ArrayIterator::seek( int $position ) Parameters: This function accepts single parameter $position which holds the position to seek. Return Value: This function does 1 min read PHP | ArrayIterator ksort() Function The ArrayIterator::ksort() function is an inbuilt function in PHP which is used to sort the array element by key. Syntax: void ArrayIterator::ksort( void ) Parameters: This function does not accept any parameters. Return Value: This function does not return any value. Below programs illustrate the A 2 min read PHP | ArrayIterator unserialize() Function The ArrayIterator::unserialize() function is an inbuilt function in PHP which is used to unserialize the serialize object. Syntax: void ArrayIterator::unserialize( string $serialized ) Parameters: This function accepts single parameter $serialized which holds the serialize array iterator object. Ret 2 min read PHP | ArrayIterator rewind() Function The ArrayIterator::rewind() function is an inbuilt function in PHP which is used to rewind the array back to the start. Syntax: void ArrayIterator::rewind( void ) Parameters: This function does not accept any parameters. Return Value: This function does not return any value. Below programs illustrat 1 min read Like