PHP | Ds\Sequence 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. 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 elementprint_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 elementprint_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
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, zambiatek Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
 
				 
					


