Collection::filter PHP 메소드

filter() 공개 메소드

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

Usage Example

예제 #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