Ds\Set::filter

(PECL ds >= 1.0.0)

Ds\Set::filter Creates a new set using a callable to determine which values to include

说明

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

Creates a new set using a callable to determine which values to include.

参数

callback

callback ( mixed $value ) : bool

Optional callable which returns TRUE if the value should be included, FALSE otherwise.

If a callback is not provided, only values which are TRUE (see converting to boolean) will be included.

返回值

A new set containing all the values for which either the callback returned TRUE, or all values that convert to TRUE if a callback was not provided.

范例

Example #1 Ds\Set::filter() example using callback function

<?php
$set 
= new \Ds\Set([12345]);

var_dump($set->filter(function($value) {
    return 
$value == 0;
}));
?>

以上例程的输出类似于:

object(Ds\Set)#3 (2) {
  [0]=>
  int(2)
  [1]=>
  int(4)
}

Example #2 Ds\Set::filter() example without a callback function

<?php
$set 
= new \Ds\Set([01'a'truefalse]);

var_dump($set->filter());
?>

以上例程的输出类似于:

object(Ds\Set)#2 (3) {
  [0]=>
  int(1)
  [1]=>
  string(1) "a"
  [2]=>
  bool(true)
}
相关文章
php cairomatrix creates a new translation matrixphp deque creates a new deque using a callable to determine which values to includephp map creates a new map using keys that aren t in another mapphp map creates a new map using a callable to determine which pairs to includephp map creates a new map using values from the current instance and another mapphp map creates a new map using keys of either the current instance or of another map but not of bothphp sequence creates a new sequence using a callable to determine which values to includephp set creates a new instancephp set creates a new set using values that aren t in another setphp set creates a new set using a callable to determine which values to includephp set creates a new set by intersecting values with another setphp set creates a new set using values from the current instance and another setphp set creates a new set using values in either the current instance or in another set but not in bothphp vector creates a new vector using a callable to determine which values to includephp ncurses 函数 set new position and draw a horizontal line using an attributed character and max. n characters longphp ncurses 函数 set new position and draw a vertical line using an attributed character and max. n characters longphp solrquery returns whether or not to include the upper bound term in the result setphp swfaction creates a new swfactionphp swftext creates a new swftext objectphp swoole atomic set a new value to the atomic object.
关注编程学问公众号