Re: [RFC Discussion] array_change_keys()
| From: | Marco Pivetta | Date: | Sun, 29 May 2016 22:18:52 +0000 |
| Subject: | Re: [RFC Discussion] array_change_keys() | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-93629@lists.php.net to get a copy of this message | ||
A bit skeptic here:
1. could you also provide the code for the benchmarks? I'd gladly measure
them with an accurate tool
2. do we really need another array function that is basically an
array_combine(array_map($someFunc, array_keys($arr)), $arr)?
3. and... do we really want another function that accepts arrays and not
generic Traversable (and therefore also generators)?
4. what is the real-world benefit over just
array_combine(array_map($someFunc, array_keys($arr)), $arr), except for
the two additional function calls here?
Cheers,
Marco Pivetta
http://twitter.com/Ocramius
http://ocramius.github.com/
On 29 May 2016 at 15:13, Colin O'Dell <colinodell@gmail.com> wrote:
> Hello everyone,
>
> I'd like to introduce a new RFC for your consideration and discussion:
> https://wiki.php.net/rfc/array_change_keys This would add a
> new function
> named array_change_keys() which simplifies the process of re-keying an
> array.
>
> PHP currently has an array_change_key_case() method, but this only allows
> keys to be changed to upper- or lower-case; no method exists to change the
> keys to some custom user-defined value. Although it's absolutely possible
> to accomplish this without a special function, the alternate approaches
> have several drawbacks:
>
> - Slower execution time compared to the proposed implementation.
> - Multiple lines and/or function calls are required.
> - Harder to understand the code's purpose with a quick glance.
> - The result of a "foreach" approach cannot be passed into another
> function without using an intermediate variable.
>
> A working implementation has been included with the RFC (huge thanks to
> Jeremy Mikola for the heavy lifting here!) I've also requested this patch
> be added to 3v4l.org; I'll notify everyone if/when that happens.
>
> I'd greatly appreciate if you could review this RFC and let me know your
> thoughts. I'd be happy to answer any questions you might have.
>
> Regards,
>
> Colin O'Dell
>