PHP | Ds\Vector sorted() Function Last Updated : 22 Aug, 2019 Comments Improve Suggest changes Like Article Like Report 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 ) Parameters: This function accepts single parameter $comparator which holds the sorting function. Return Value: This function returns a copy of sorted vector. Below programs illustrate the Ds\Vector::sorted() function in PHP: Program 1: PHP <?php // Declare new Vector $vect = new \Ds\Vector([6, 5, 4, 3, 2, 1]); echo("Original vector\n"); // Display the vector elements var_dump($vect); // Use sorted() function to sort // the copy of vector elements $res = $vect->sorted(); echo("\nSorted elements\n"); // Display the sorted elements var_dump($res); ?> Output: Original vector object(Ds\Vector)#1 (6) { [0]=> int(6) [1]=> int(5) [2]=> int(4) [3]=> int(3) [4]=> int(2) [5]=> int(1) } Sorted elements object(Ds\Vector)#2 (6) { [0]=> int(1) [1]=> int(2) [2]=> int(3) [3]=> int(4) [4]=> int(5) [5]=> int(6) } Program 2: PHP <?php // Declare new Vector $vect = new \Ds\Vector([3, 6, 1, 2, 9, 7]); echo("Original vector\n"); // Display the vector elements var_dump($vect); // Use sorted() function to sort // the copy of vector elements $res = $arr->sorted(function($element1, $element2) { return $element1 <=> $element2; }); echo("\nSorted elements\n"); // Display the sorted elements var_dump($res); ?> Output: Original vector object(Ds\Vector)#1 (6) { [0]=> int(3) [1]=> int(6) [2]=> int(1) [3]=> int(2) [4]=> int(9) [5]=> int(7) } Sorted elements object(Ds\Vector)#3 (6) { [0]=> int(1) [1]=> int(2) [2]=> int(3) [3]=> int(6) [4]=> int(7) [5]=> int(9) } Reference: http://php.net/manual/en/ds-vector.sorted.php Comment More infoAdvertise with us Next Article PHP | DsMap sort() Function B barykrg Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-ds_vector 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 | DsMap reverse() Function The Ds/Map::reverse() function in PHP is used to in-place reverse the elements of a specified Map instance. That is, the function in-place reverses the order of elements present in the specified Map instance. Syntax: Ds\Map public Ds\Map::reverse ( int $position ) Parameter: This function does not a 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 | 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 sort() Function The sort() function is an inbuilt function in PHP and is used to sort an array in ascending order i.e, smaller to greater. It sorts the actual array and hence changes are reflected in the original array itself. The function provides us with 6 sorting types, according to which the array can be sorted 3 min read PHP | DsDeque reverse() Function The Ds\Deque::reverse() function is an inbuilt function in PHP which is used to reverse the elements in the Deque in-place. Syntax: public Ds\Deque::reverse( void ) : void Parameters: This function does not accept any parameter. Return Value: This function does not return any value. Below programs i 2 min read Like