Re: [RFC Discussion] array_change_keys()
| From: | Thomas Nunninger | Date: | Sun, 29 May 2016 14:00:42 +0000 |
| Subject: | Re: [RFC Discussion] array_change_keys() | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-93623@lists.php.net to get a copy of this message | ||
Hello,
shouldn't it be possible to return null as new key? That way you say: Use the next free integer index.
Not sure if returning null is wanted (as it could hide errors in the callback) or needed in some real world use cases. But it would be more in sync with $a[] = ...
Regards
Thomas
On 05/29/2016 03:13 PM, Colin O'Dell 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