PHP | Ds\Set sorted() Function
The Ds\Set::sorted() function is an inbuilt function in PHP which is used to return a sorted copy of given set. Syntax:
Ds\Set public Ds\Set::sorted ([ 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 the second element.
- -1: if the first element is expected to be greater than the second element.
- 0: if the first element is expected to be equal to the second element.
Return value: It returns the sorted copy of the given set. Below programs illustrate the Ds\Set::sorted() function in PHP: Program 1:
\Ds\Set([20, 10, 30]);
 => 10
 => 20
 => 30
\Ds\Set([2, 3, 6, 5, 7, 1, 4]);
 => 7
 => 6
 => 5
 => 4
 => 3
 => 2
 => 1
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses
are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!