Illuminate\Support\Collection::whereIn PHP Method

whereIn() public method

Filter items by the given key value pair.
public whereIn ( string $key, mixed $values, boolean $strict = false ) : static
$key string
$values mixed
$strict boolean
return static
    public function whereIn($key, $values, $strict = false)
    {
        $values = $this->getArrayableItems($values);
        return $this->filter(function ($item) use($key, $values, $strict) {
            return in_array(data_get($item, $key), $values, $strict);
        });
    }

Usage Example

Example #1
0
 public function testWhereIn()
 {
     $c = new Collection([['v' => 1], ['v' => 2], ['v' => 3], ['v' => '3'], ['v' => 4]]);
     $this->assertEquals([['v' => 1], ['v' => 3]], $c->whereIn('v', [1, 3])->values()->all());
 }