PHP | Ds\Deque sort() Function Last Updated : 14 Aug, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 how to sort the elements. It helps in customizing the sort function. Return Value: This function does not return any value. Below programs illustrate the Ds\Deque::sort() function in PHP: Program 1: PHP <?php // Declare a deque $deck = new \Ds\Deque([5, 6, 3, 2, 7, 1]); echo("Elements of Deque\n"); // Display the Deque elements print_r($deck); // Use sort() function to sort // the elements $deck->sort(); echo("Sorted Deque\n"); // Display the Deque elements print_r($deck);; ?> Output: Elements of Deque Ds\Deque Object ( [0] => 5 [1] => 6 [2] => 3 [3] => 2 [4] => 7 [5] => 1 ) Sorted Deque Ds\Deque Object ( [0] => 1 [1] => 2 [2] => 3 [3] => 5 [4] => 6 [5] => 7 ) Program 2: PHP <?php // Declare a deque $deck = new \Ds\Deque([5, 6, 3, 2, 7, 1]); echo("Elements of Deque\n"); // Display the Deque elements print_r($deck); // comparator to sort in reverse order $deck->sort(function($first, $second) { return $first <= $second; }); echo("Sorted Deque\n"); // Display the Deque elements print_r($deck);; ?> Output: Elements of Deque Ds\Deque Object ( [0] => 5 [1] => 6 [2] => 3 [3] => 2 [4] => 7 [5] => 1 ) Sorted Deque Ds\Deque Object ( [0] => 7 [1] => 6 [2] => 5 [3] => 3 [4] => 2 [5] => 1 ) Reference: http://php.net/manual/en/ds-deque.sort.php Comment More infoAdvertise with us Next Article PHP | DsDeque sorted() Function B barykrg Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-ds_deque Similar Reads 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 | 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 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 | 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 | 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 | Ds\Deque sort() Function min read Like