Skip to content
Related Articles

Related Articles

Improve Article
PHP | Ds\Sequence sorted() Function
  • Last Updated : 22 Aug, 2019

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 then or greater then 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
   
// 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
   
// 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

My Personal Notes arrow_drop_up
Recommended Articles
Page :