Collection::filter PHP Method

filter() public method

Filter the elements in the array by a callback function
public filter ( func $callback ) : Collection
$callback func the callback function
return Collection
    public function filter($callback)
    {
        $collection = clone $this;
        $collection->data = array_filter($collection->data, $callback);
        return $collection;
    }

Usage Example

Exemplo n.º 1
0
 /**
  * @test Collection::filter()
  */
 public function testFilter()
 {
     $this->buildEnvironment();
     $result = $this->collection->filter('prop2', '>', 2)->fetch();
     $expect = $this->source;
     unset($expect['a1']);
     $this->assertEquals($expect, $result);
     $result = $this->collection->filter('prop2', '>=', 2)->fetch();
     $expect = $this->source;
     $this->assertEquals($expect, $result);
 }
All Usage Examples Of Collection::filter