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. The comparison function returns an integer value which is less than or greater than or equal to zero. Return value: This function returns the sorted copy of sequence. Below programs illustrate the Ds\Sequence::sorted() function in PHP: Program 1:
php
<?php // Create new sequence $seq = new \Ds\Vector([2, 4, 1, 9, 6, 5, 12, 9]); // Use sorted() function to sort // the sequence element print_r( $seq ->sorted()); ?> |
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(["Geeks", "GFG", "Abc", " for "]); // Use sorted() function to sort // the sequence element print_r( $seq ->sorted()); ?> |
Output:
Ds\Vector Object ( [0] => Abc [1] => GFG [2] => Geeks [3] => for )
Reference: http://php.net/manual/en/ds-sequence.sorted.php