PHP Ds\Sequence sort() Function Last Updated : 26 Apr, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 function. The comparison function returns an integer value less than, greater than, or equal to zero. Return value: This function does not return any values. Below programs illustrate the Ds\Sequence::sort() function in PHP: Program 1: php <?php // Create new sequence $seq = new \Ds\Vector([2, 4, 1, 9, 6, 5, 12, 9]); // Use sort() function to sort // the sequence element $seq->sort(); print_r($seq); ?> 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([2, 4, 1, 9, 6, 5, 12, 9]); // Use sort() function to sort // the sequence element $seq->sort(function($x, $y) { return $y <=> $x; }); print_r($seq); ?> Output: Ds\Vector Object ( [0] => 12 [1] => 9 [2] => 9 [3] => 6 [4] => 5 [5] => 4 [6] => 2 [7] => 1 ) Reference: http://php.net/manual/en/ds-sequence.sort.php Comment More infoAdvertise with us Next Article PHP | DsMap sort() Function V vijay_raj Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-DS\Collection Similar Reads 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 | 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 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 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 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 Like