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 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 hyperwave api 函数 creates a new instance of class hwapi object newphp 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 gmagick creates a new imagephp harupage set starting point for new drawing pathphp sphinxclient set attribute name for per group distinct values count calculationsphp splstack constructs a new stack implemented using a doubly linked list
关注编程学问公众号