Re: array_reduce callback key
| From: | Rob Landers | Date: | Wed, 17 Jul 2024 08:07:52 +0000 |
| Subject: | Re: array_reduce callback key | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-124455@lists.php.net to get a copy of this message | ||
On Wed, Jul 17, 2024, at 09:55, Lily Bergonzat wrote:
> While it *is* indeed a workaround, you can very easily
> access the values of the array from the keys, since that
> literally is what the keys are for.
>
> While I also think it's weird that not all php array functions
> with callbacks do pass the key as an argument, and while
> I also stumbled upon that problem in the past myself
> multiple times, I also think it is worth taking the time to
> consider what other people from this mailing list are
> bringing up. If it could indeed break internal callbacks,
> then I think using the workaround could be a better idea
> than potentially breaking other things.
>
> On Wed, Jul 17, 2024 at 2:38 AM Bilge <bilge@scriptfusion.com> wrote:
> >
> > On Wed, 17 Jul 2024, 01:29 mickmackusa, <mickmackusa@gmail.com> wrote:
> >>
> >> It is untrue that you "can't access it"; you just need to use an array
> >> of keys as the input array.
> >
> > It is absolutely true and your workaround is just that; a workaround that doesn't
> > work at all when you also need the value.
> >
> > Cheers,
> > Bilge
>
If it can be the last argument, then PHP doesn't care if you call a function with extra
arguments ... at least, it usually doesn't.
— Rob