Skip to content
Snippets Groups Projects

3395880-Implement the whereInStrict method for Collection class

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