PHP | Ds\Sequence sorted() Function Last Updated : 13 Jul, 2022 Comments Improve Suggest changes Like Article Like Report The Ds\Sequence::sorted() function is an inbuilt function in PHP which is used to return the sorted copy of sequence element. Syntax: Ds\Sequence abstract public Ds\Sequence::sorted( $comparator ) Parameters: This function accepts a single parameter $comparator which holds the comparison function. The comparison function returns an integer value which is less than or greater than or equal to zero. Return value: This function returns the sorted copy of sequence. Below programs illustrate the Ds\Sequence::sorted() function in PHP: Program 1: php <?php // Create new sequence $seq = new \Ds\Vector([2, 4, 1, 9, 6, 5, 12, 9]); // Use sorted() function to sort // the sequence element print_r($seq->sorted()); ?> Output: Ds\Vector Object ( [0] => 1 [1] => 2 [2] => 4 [3] => 5 [4] => 6 [5] => 9 [6] => 9 [7] => 12 ) Program 2: php <?php // Create new sequence $seq = new \Ds\Vector(["Geeks", "GFG", "Abc", "for"]); // Use sorted() function to sort // the sequence element print_r($seq->sorted()); ?> Output: Ds\Vector Object ( [0] => Abc [1] => GFG [2] => Geeks [3] => for ) Reference: http://php.net/manual/en/ds-sequence.sorted.php Comment More infoAdvertise with us Next Article PHP uasort() Function V vijay_raj Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-DS\Collection Similar Reads PHP | DsSet 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 2 min read PHP | DsDeque sorted() Function The Ds\Deque::sorted() function is an inbuilt function in PHP which is used to return a copy of Deque which contains the element in the original Deque in increasing order. Syntax: public Ds\Deque::sorted( $comparator ) : Ds\Deque Parameters: This function accepts single parameter $comparator which h 2 min read PHP | DsVector sorted() Function The Ds\Vector::sorted() function is an inbuilt function in PHP which is used to sort the elements of the vector by creating a copy of the original vector. This will arrange the vector elements in increasing order using default comparator. Syntax: Ds\Vector public Ds\Vector::sorted( $comparator ) Par 2 min read PHP | DsMap sort() Function The Ds\Map::sort() function of DS\Map class in PHP is used to in-place sort the elements of a specified Map instance according to the values. By default, the Map is sorted according to the increasing order of the values. Syntax: Ds\Pair public Ds\Map::sort ( int $position ) Parameter: This function 2 min read PHP DsSet sort() Function 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. Syntax: void public Ds\Set::sort ([ callable $comparator ] ) Parameters: This f 2 min read PHP usort() Function PHP comes with a number of built-in functions that are used to sort arrays in an easier way. Here, we are going to discuss a new function usort(). The usort() function in PHP sorts a given array by using a user-defined comparison function. This function is useful in case if we want to sort the array 2 min read PHP | DsSequence sorted() Function The Ds\Sequence::sorted() function is an inbuilt function in PHP which is used to return the sorted copy of sequence element. Syntax: Ds\Sequence abstract public Ds\Sequence::sorted( $comparator ) Parameters: This function accepts a single parameter $comparator which holds the comparison function. T 1 min read PHP uasort() Function The uasort() function is a builtin function in PHP and is used to sort an array such that array indices maintain their correlation with the array elements they are associated with, using a user-defined comparison function. Syntax: boolean uasort(array_name, user_defined_function); Parameter: This fu 3 min read PHP DsSet reversed() Function The Ds\Set::reversed() function of Ds\Set class in PHP is an inbuilt function which is used to create a copy of the original Set with values arranged in reverse order. That is, this function returns a reversed copy of the actual set. This function does not affect the original set instance. Syntax: D 2 min read PHP uksort() Function The uksort() function is a built-in function in PHP and is used to sort an array according to the keys and not values using a user-defined comparison function. Syntax:boolean uksort($array, myFunction);Parameter: This function accepts two parameters which are described below: $array: This parameter 2 min read Like