This is not the first time that a developer needs access to the input array's keys within the callback of array_reduce(). It is untrue that you "can't access it"; you just need to use an array of keys as the input array.
Some frameworks already have the feature of key access built into their methods/functions. https://laravel.com/docs/11.x/collections#method-reduce Examples of passing array_keys to array_reduce (some of which are more than a decade old): https://stackoverflow.com/a/10196070/2943403 https://stackoverflow.com/a/27419768/2943403 https://stackoverflow.com/a/27809675/2943403 https://stackoverflow.com/a/32226816/2943403 https://stackoverflow.com/a/33372066/2943403 https://stackoverflow.com/a/37728665/2943403 https://stackoverflow.com/a/39322532/2943403 https://stackoverflow.com/a/45508817/2943403 https://stackoverflow.com/a/48664250/2943403 https://stackoverflow.com/a/49035053/2943403 https://stackoverflow.com/a/57966850/2943403 https://stackoverflow.com/a/58997848/2943403 https://stackoverflow.com/a/73726419/2943403 https://stackoverflow.com/a/76196482/2943403 mickmackusa On Wed, 17 Jul 2024, 09:15 Bilge, <bi...@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 >