DsSet public DsSet::sorted ([callable $comparator]) Parameters :
This function takes a comparator function according to which the values are compared when sorting the set. The comparator should return the following values based on a comparison of the 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 larger than the second element.
- 0:if the first is expected the element will be equal to the second element.
Returns a sorted copy of the given set.The programs below illustrate the Ds / Set function::sorted()
in PHP:Program 1:
// PHP program to illustrate the sorted() function
DsSet ([20, 10, 30]);
// sort the set
DsSet Object (  = > 10  = > 20  = > 30) Program 2:
// Declare new set
DsSet ([2, 3, 6, 5, 7, 1, 4]);
-> sorted (
< = >
DsSet Object (  = > 7  = > 6  = > 5  = > 4  = > 3  = > 2  = > 1) Link: https://www.php. net / manual / en / ds-set.sorted.php