PHP Ds\Sequence 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 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
$seq = new \Ds\Vector([2, 4, 1, 9, 6, 5, 12, 9]);
$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
$seq = new \Ds\Vector([2, 4, 1, 9, 6, 5, 12, 9]);
$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
Last Updated :
26 Apr, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...