PHP | Ds\Vector sort() Function Last Updated : 22 Aug, 2019 Comments Improve Suggest changes Like Article Like Report The Ds\Vector::sort() function is an inbuilt function in PHP which is used to sort the elements of vector in-place. This will arrange the vector elements in increasing order. Syntax: void public Ds\Vector::sort( $comparator ) Parameters: This function accepts a single parameter $comparator which is used to hold the sort function. Return Value: This function does not returns any value. Below programs illustrate the Ds\Vector::sort() 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 print_r($vect); // Use sort() function to sort // the vector elements $vect->sort(); echo("\nSorted elements\n"); // Display the sorted vector // elements print_r($vect); ?> Output: Original vector Ds\Vector Object ( [0] => 6 [1] => 5 [2] => 4 [3] => 3 [4] => 2 [5] => 1 ) Sorted elements Ds\Vector Object ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 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 print_r($vect); // Use sort() function to sort // the vector elements $vect->sort(function($element1, $element2) { return $element2 <=> $element1; }); echo("\nDecreasing Sorted elements\n"); // Display the sorted vector // elements print_r($vect); ?> Output: Original vector Ds\Vector Object ( [0] => 3 [1] => 6 [2] => 1 [3] => 2 [4] => 9 [5] => 7 ) Decreasing Sorted elements Ds\Vector Object ( [0] => 9 [1] => 7 [2] => 6 [3] => 3 [4] => 2 [5] => 1 ) Reference: http://php.net/manual/en/ds-vector.sort.php Comment More infoAdvertise with us 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 | 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 | 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 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 | 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 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 rsort() Function The rsort() is an inbuilt function in PHP and is used to sort the array in descending order i.e, greatest to smallest. It sorts the actual array and hence changes are reflected in the array itself. The function provides us with 6 sorting types, according to which the array can be sorted. Syntax: rso 3 min read PHP | DsVector sort() Function The Ds\Vector::sort() function is an inbuilt function in PHP which is used to sort the elements of vector in-place. This will arrange the vector elements in increasing order. Syntax: void public Ds\Vector::sort( $comparator ) Parameters: This function accepts a single parameter $comparator which is 2 min read Like