rfc:array_change_keys
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:array_change_keys [2016/05/30 03:31] – Updated userland implementation colinodell | rfc:array_change_keys [2018/11/27 23:34] (current) – Withdrawing the RFC colinodell | ||
---|---|---|---|
Line 3: | Line 3: | ||
* Date: 2016-05-29 | * Date: 2016-05-29 | ||
* Authors: Colin O'Dell < | * Authors: Colin O'Dell < | ||
- | * Status: | + | * Status: |
* First Published at: http:// | * First Published at: http:// | ||
Line 32: | Line 32: | ||
$newArray = array_combine( | $newArray = array_combine( | ||
array_map( | array_map( | ||
- | function ($value) { | + | function ($key, $value) { |
return ' | return ' | ||
}, | }, | ||
Line 52: | Line 52: | ||
===== Proposal ===== | ===== Proposal ===== | ||
This RFC proposes the creation of a new core function '' | This RFC proposes the creation of a new core function '' | ||
+ | |||
+ | <code php> | ||
+ | $newArray = array_change_keys($originalArray, | ||
+ | return ' | ||
+ | }); | ||
+ | </ | ||
+ | |||
+ | Function definition: | ||
<code php> | <code php> | ||
Line 105: | Line 113: | ||
==== Function Name ==== | ==== Function Name ==== | ||
- | PHP already has an '' | + | PHP already has an '' |
- | Other function | + | Other functions |
===== Discussion ===== | ===== Discussion ===== | ||
Line 115: | Line 123: | ||
==== Pros ==== | ==== Pros ==== | ||
- | === Faster Execution | + | === Provides Common General-Purpose Functionality |
- | Re-keying | + | PHP already has an '' |
- | {{: | + | === Usefulness === |
+ | |||
+ | Needing to re-key array is a common task for some PHP developers, especially those needing their array to work like a dictionary. | ||
=== Cleaner Code === | === Cleaner Code === | ||
Using this function makes it immediately obvious to other developers that an array is being re-keyed. | Using this function makes it immediately obvious to other developers that an array is being re-keyed. | ||
+ | |||
+ | === Matches Existing Behavior === | ||
+ | |||
+ | The "edge cases" mentioned above (returning invalid types or duplicate keys) matches existing behavior in PHP that developers already understand and expect. | ||
+ | |||
+ | === Faster Execution Than array_combine() === | ||
+ | |||
+ | Re-keying an array with '' | ||
+ | |||
+ | {{: | ||
+ | |||
+ | {{: | ||
+ | |||
+ | (Benchmarks generated with https:// | ||
+ | |||
+ | === Works With Functional Code === | ||
+ | |||
+ | This function can be nested inside of other method calls for function composition. | ||
==== Cons ==== | ==== Cons ==== | ||
+ | |||
+ | === Slower Than foreach === | ||
+ | |||
+ | As noted in the benchmarks above, the '' | ||
+ | |||
+ | === Does Not Support Traversable === | ||
+ | |||
+ | Like the other '' | ||
+ | |||
+ | === Easily Implemented In User Land === | ||
+ | |||
+ | This function can be implemented in user land using one of the alternative approaches shown above. | ||
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== | ||
Line 148: | Line 188: | ||
===== Future Scope ===== | ===== Future Scope ===== | ||
- | Returning | + | Other '' |
- | ===== Proposed | + | ===== Voting ===== |
Because this is not a language change, a 50%+1 vote will be required to add this new function. | Because this is not a language change, a 50%+1 vote will be required to add this new function. | ||
Line 160: | Line 200: | ||
===== References ===== | ===== References ===== | ||
Links to external references, discussions or RFCs | Links to external references, discussions or RFCs | ||
+ | |||
+ | Mailing list discussion: [[https:// | ||
+ | |||
+ | Reddit discussion: [[https:// |
rfc/array_change_keys.1464579111.txt.gz · Last modified: 2017/09/22 13:28 (external edit)