Filter

Filter ( [ callable $callback ] )

Passes every input value to the callback function, returning only values for which the callback returns true.

Parameters

callback
bool callback ( mixed $value )

If no callback is supplied, all values that equal false (after being converted to bool) are removed.

value
The current value.

Examples

Example #1

Basic usage example.

<?php
use Webbhuset\Pipeline\Constructor as F;

$filter = F::Filter(function ($value) {
    return $value % 2 == 0;
});

$input = [1, 2, 3, 4, 5, 6, 7, 8];

echo json_encode(iterator_to_array($filter($input)));

// Output: [2,4,6,8]

See Also

  • Drop - Discard a specific amount of input values.
  • DropWhile - Discard input values while a callback function returns true.