You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Suggested Solution Since PHP 5.6 we are able to specify a flag on array_filter which allows to filter the element of the array by passing to the closure that filter the array, key, value or both
array array_filter ( array $array [, callable $callback [, int $flag = 0 ]] )
Flag determining what arguments are sent to callback:
ARRAY_FILTER_USE_KEY - pass key as the only argument to callback instead of the value
ARRAY_FILTER_USE_BOTH - pass both value and key as arguments to callback instead of the value
Default is 0 which will pass value as the only argument to callback instead.
Suggested Implementation
At the moment ArrayCollection#filter uses the default value 0 which makes the flag feature impossible to use.
- public function filter(Closure$p)
+ public function filter(Closure$p, int $flag = 0)
{
- return $this->createFrom(array_filter($this->elements, $p));
+ return $this->createFrom(array_filter($this->elements, $p, $flag));
}
Concerns
I understand that exposing lower level APIs to an higher level of abstraction is not probably a good idea. Yet, the additional feature would be useful overall to the client who uses the method
If you provide some feedback I can submit a PR
The text was updated successfully, but these errors were encountered:
Using the default value for $flag = 0 does not introduce a BC Break as it is the default behaviour of array_filter. I will update this issue as soon as I have a PR.
Scenario
I want be able to filter an array by key or both (key, value)
Suggested Solution
Since PHP 5.6 we are able to specify a flag on
array_filter
which allows to filter the element of the array by passing to the closure that filter the array, key, value or bothSuggested Implementation
At the moment ArrayCollection#filter uses the default value 0 which makes the flag feature impossible to use.
Concerns
I understand that exposing lower level APIs to an higher level of abstraction is not probably a good idea. Yet, the additional feature would be useful overall to the client who uses the method
If you provide some feedback I can submit a PR
The text was updated successfully, but these errors were encountered: