PHP | Ds\Map::ksort() Function Last Updated : 20 Aug, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report The Ds\Map::ksort() function is an inbuilt function in PHP, which is used to sort the map element in-place by key. Syntax: void public Ds\Map::ksort ([ callable $comparator ] ) Parameter: This function accepts single parameter $comparator which contains function according to which the values will be compared while sorting the copy of the Map. The comparator should return the following values based on the comparison of two values passed to it as a parameter: 1, if the first element is expected to be less than second element. -1, if the first element is expected to be greater than second element. 0, if the first element is expected to be equal to the second element. Return value: This function does not return any value. Below programs illustrate the Ds\Map::ksort() function in PHP: Program 1: php <?php // PHP program to illustrate ksort() function // Declare a Map $map = new \Ds\Map([1 => 20, 3 => 10, 2 => 30]); // Sort the Map element by key $map->ksort(); // Display the map element print_r($map); ?> Output: Ds\Map Object ( [0] => Ds\Pair Object ( [key] => 1 [value] => 20 ) [1] => Ds\Pair Object ( [key] => 2 [value] => 30 ) [2] => Ds\Pair Object ( [key] => 3 [value] => 10 ) ) Program 2: php <?php // PHP program to illustrate ksort() function // Declare a Map $map = new \Ds\Map(["x" => "Geeks", "a" => "for", "z" => "Geeks"]); // Sort the Map element by key $map->ksort(); // Display sorted element print_r($map); ?> Output: Ds\Map Object ( [0] => Ds\Pair Object ( [key] => a [value] => for ) [1] => Ds\Pair Object ( [key] => x [value] => Geeks ) [2] => Ds\Pair Object ( [key] => z [value] => Geeks ) ) Reference: https://www.php.net/manual/en/ds-map.ksort.php Comment More infoAdvertise with us Next Article PHP | Ds\Map::ksort() Function R R_Raj Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-ds_map Similar Reads PHP ksort() Function 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. Syntax: bool ksort( $array, $sorting_type ) Parameters: This function accepts two pa 3 min read PHP krsort() Function The krsort() function is an inbuilt function in PHP which is used to sort an array by key in reverse order according to its index values. It sorts in a way that relation between indices and values is maintained. Syntax: bool krsort( $array, $sorting_type ) Parameters: This function accepts two param 2 min read PHP | DsDeque map() Function The Ds\Deque::map() function is an inbuilt function in PHP which is used to return the Deque with each element modified on the basis of operation performed as per the callback function. Syntax: public Ds\Deque::map( $callback ) : Ds\Deque Parameters: This function accepts single parameter $callback 2 min read PHP | DsVector map() Function The Ds\Vector::map() function is an inbuilt function in PHP which is used to return the result of a callback after applying to each value in the vector. Syntax: Ds\Vector public Ds\Vector::map( $callback ) Parameters: This function accepts single parameter $callback which is to be applied to each ve 2 min read PHP | DsSequence map() Function The Ds\Sequence::map() function is an inbuilt function in PHP which returns the result after applying callback function to each value. Syntax: Ds\Sequence abstract public Ds\Sequence::map( $callback ) Parameter: This function accepts single parameter $callback. The callback apply on each value of se 1 min read Like