rfc:array_change_keys
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
rfc:array_change_keys [2016/05/30 03:33] – Fix error in previous change; show example usage under Proposal colinodell | rfc:array_change_keys [2016/05/31 01:32] – Update pros & cons colinodell | ||
---|---|---|---|
Line 57: | Line 57: | ||
return ' | return ' | ||
}); | }); | ||
+ | </ | ||
+ | |||
+ | Function definition: | ||
+ | |||
+ | <code php> | ||
+ | array array_change_keys(array $originalArray, | ||
</ | </ | ||
Line 117: | 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. | ||
+ | |||
+ | === 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 ===== |
rfc/array_change_keys.txt · Last modified: 2018/11/27 23:34 by colinodell