-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Added "key" parameter to array_reduce
callback
#14986
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
guess it's worth mentioning that it can easily be built in userland? function array_reduce_with_key(array $array, callable $callback, mixed $initial = null): mixed
{
$result = $initial;
foreach ($array as $key => $value) {
$result = $callback($result, $value, $key);
}
return $result;
} |
I don't think that's worth mentioning, unless you can justify why it precludes the usefulness of having it in core? |
well there is a backwards-compatibility concern, for example
today generates
but in your branch presumably generates
it might not be worth the BC break to do it in core (i don't know) edit: would not affect the vast majority of code in the wild (as you said in the ML, most functions don't care about an extra argument.. but exceptions exist) |
This would indeed require an RFC because there's a BC concern, even though the BC impact is likely limited. |
the bc problem could be resolved by adding a 4th argument |
This changes the signature of the
array_reduce
callback from:to: