• PHP Video Tutorials

PHP - Ds Sequence sort() Function


Advertisements

Ds\Sequence::sort() function can sort a sequence in-place.

Syntax

public abstract void Ds\Sequence::sort([ callable $comparator ] )

Ds\Sequence::sort() function can sort a sequence in-place by using an optional comparator function.

Ds\Sequence::sort() function doesn't return any value.

Example 1

<?php 
   $seq = new \Ds\Vector([2, 7, 1, 9, 6, 15, 12, 20]); 
   $seq->sort(); 
   
   print_r($seq); 
?>

Example-2

<?php 
   $seq = new \Ds\Vector([2, 7, 1, 9, 6, 5, 12, 20]); 
   $seq->sort(function($x, $y) { 
      return $y <=> $x; 
   }); 
   print_r($seq); 
?>
php_function_reference.htm
Advertisements