public function Collection::filter

Same name in this branch

Iterates over each key value pair in the collection passing them to the Closure. If the Closure function returns true, the current value from input is returned into the result Collection. The Closure must accept three parameters: (string) $key, (string) $value and return Boolean TRUE or FALSE for each value.

Parameters

\Closure $closure Closure evaluation function:

bool $static Set to TRUE to use the same class as the return rather than returning a Collection:

Return value

Collection

File

drupal/core/vendor/guzzle/common/Guzzle/Common/Collection.php, line 108

Class

Collection
Key value pair collection object

Namespace

Guzzle\Common

Code

public function filter(\Closure $closure, $static = true) {
  $collection = $static ? new static() : new self();
  foreach ($this->data as $key => $value) {
    if ($closure($key, $value)) {
      $collection
        ->add($key, $value);
    }
  }
  return $collection;
}