• PHP Video Tutorials

PHP - Ds Set sort() Function



Ds\Set::sort() function can sort a set in-place.

Syntax

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

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

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

Example 1

<?php 
   $set = new \Ds\Set([20, 10, 30, 50, 40]); 
   $set->sort(); 
   
   print_r($set); 
?>

Example 2

<?php
   $set = new \Ds\Set([4, 5, 1, 3, 2]);
   $set->sort(function($x, $y) {
      return $y <=> $x;
   });
   print_r($set);
?>
php_function_reference.htm
Advertisements