• PHP Video Tutorials

PHP - Ds Set filter() Function



Ds\Set::filter() function can create the new set by using a callable to determine which values to include.

Syntax

public Ds\Set Ds\Set::filter([ callable $callback ] )

Ds\Set::filter() function can return a new set containing all values for which either the callback returned true or all values that convert to true if a callback was not provided.

Example 1

<?php  
   $set = new \Ds\Set([10, 15, 20, 25, 30]);  
   
   var_dump($set->filter(function($val) {  
      return $val % 5 == 0;  
   }));  
?> 

Example 2

<?php  
   $set = new \Ds\Set([3, 7, 1, 9, 2, 5]);  
   
   var_dump($set->filter(function($val) {  
      return $val;  
   }));  
?> 
php_function_reference.htm
Advertisements