PHP | Ds\Deque sorted() Function Last Updated : 14 Aug, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 holds the comparator function to sorts the Deque. Return Value: This function returns a Deque which contains elements of original Deque in the sorted order. Below programs illustrate the Ds\Deque::sorted() function in PHP: Program 1: PHP <?php // Declare a deque $deck = new \Ds\Deque([4, 5, 3, 2, 8, 1, 9]); echo("Elements of Deque\n"); // Display the Deque elements print_r($deck); echo("Sorted Deque\n"); // Use sorted() function to // sort Deque elements print_r($deck->sorted()); ?> Output: Elements of Deque Ds\Deque Object ( [0] => 4 [1] => 5 [2] => 3 [3] => 2 [4] => 8 [5] => 1 [6] => 9 ) Sorted Deque Ds\Deque Object ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 8 [6] => 9 ) Program 2: PHP <?php // Declare a deque $deck = new \Ds\Deque([4, 5, 3, 2, 8, 1, 9]); echo("Elements of Deque\n"); // Display the Deque elements print_r($deck); // Use comparator function to sort elements $deck = $deck->sorted(function($var1, $var2) { return $var1 <= $var2; }); echo("Sorted Deque\n"); // Use sorted() function to // sort Deque elements print_r($deck); ?> Output: Elements of Deque Ds\Deque Object ( [0] => 4 [1] => 5 [2] => 3 [3] => 2 [4] => 8 [5] => 1 [6] => 9 ) Sorted Deque Ds\Deque Object ( [0] => 9 [1] => 8 [2] => 5 [3] => 4 [4] => 3 [5] => 2 [6] => 1 ) Reference: http://php.net/manual/en/ds-deque.sorted.php Comment More infoAdvertise with us Next Article PHP | DsDeque sort() Function B barykrg Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-ds_deque Similar Reads 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 | DsDeque sort() Function The Ds\Deque::sort() function is an inbuilt function in PHP which is used to sort the Deque in place by arranging the elements in increasing order. Syntax: public Ds\Deque::sort( $comparator ) : void Parameters::This function accepts single parameter $comparator which holds the function to decides h 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 | 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 DsSequence sort() Function The Ds\Sequence::sort() function is an inbuilt function in PHP that is used to sort the sequence element in the same place. Syntax: void abstract public Ds\Sequence::sort ([ callable $comparator ] ) Parameters: This function accepts a single parameter $comparator which is used to hold the comparison 2 min read PHP | DsDeque set() Function The Ds\Deque::set() function is an inbuilt function in PHP which is used to set the value at the given index in the Deque. Syntax: public Ds\Deque::set( $index, $value ) : void Parameters: This function accept two parameters as mentioned above and described below: index: This parameter holds the ind 2 min read PHP | Ds\Deque sorted() Function min read Like