Skip to content
Snippets Groups Projects

3395879-Implement the whereIn method for Collection class

1 file
+ 20
0
Compare changes
  • Side-by-side
  • Inline
+ 20
0
@@ -74,4 +74,24 @@ class Collection extends BaseCollection {
};
}
/**
* Filter items where the value of a given key is within a given array.
*
* @param string $key
* @param mixed $values
* @param bool $strict
* @return \Drupal\fluent\Collection
*/
public function whereIn($key, $values, $strict = false)
{
return $this->filter(function ($item) use ($key, $values, $strict) {
if ($item instanceof ContentEntityInterface) {
$value = using($item)->value($key);
return in_array($value, $values, $strict);
} else {
return in_array(data_get($item, $key), $values, $strict);
}
});
}
}
Loading