The Ds\Set::sort() function of DS\Set class in PHP is used to in-place sort the elements of a specified Set instance according to the values. By default, the Set is sorted according to the increasing order of the values.
void public Ds\Set::sort ([ callable $comparator ] )
Parameters: This function accepts a comparator function according to which the values will be compared while sorting the Set. 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: The function does not returns any value. It just sorts the specified Set instance according to the comparator function passed.
Below programs illustrate the Ds\Set::sort() function:
Ds\Set Object (  => 10  => 20  => 30 )
Ds\Set Object (  => 30  => 20  => 10 )
- PHP | Ds\Map sort() Function
- PHP | sort() Function
- PHP | Ds\Vector sort() Function
- PHP | Ds\Sequence sort() Function
- PHP | Ds\Deque sort() Function
- Sort an array of dates in PHP
- Sort a multidimensional array by date element in PHP
- Sort array of objects by object fields in PHP
- PHP | Sort array of strings in natural and standard orders
- PHP | end() Function
- PHP Ds\Map first() Function
- PHP Ds\Map sum() Function
- PHP | pos() Function
- PHP | abs( ) Function
- PHP | Ds\Set contains() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.