Re: array_reduce callback key
| From: | Levi Morrison | Date: | Wed, 17 Jul 2024 00:41:06 +0000 |
| Subject: | Re: array_reduce callback key | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-124453@lists.php.net to get a copy of this message | ||
On Tue, Jul 16, 2024 at 5:17 PM Bilge <bilge@scriptfusion.com> wrote:
>
> Hi Internals,
>
> I just ran into a case where I needed the array key in an array_reduce()
> callback, but I can't access it :(
>
> So I wrote a PR to fix it:
> https://github.com/php/php-src/pull/14986
>
> What do you think? Does this need an RFC?
>
> Cheers,
> Bilge
I don't think it's reasonable to cover every use-case "nicely" in the
standard library. You didn't give a real example. You might consider
using array_walk or iterator_apply, or a foreach loop depending on
what you need.
I am curious what your real use-case is. It may be worth adding
something. It might not. Hard to tell. Adding arguments to a function
can mess up internal callbacks, btw, so I don't like modifying the
existing function.