Download the PHP package dakujem/remapkeys without Composer
On this page you can find all versions of the php package dakujem/remapkeys. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package remapkeys
Remap Keys
💿
composer require dakujem/remapkeys
This package adds a pair of functions similar to array_map
that are commonly used when working with arrays:
array_remap
- like
array_map
, but allows to specify/map indexes of the result
- like
array_map_keys
- like
array_map
, but passes indexes to the iteratee function and preserves indexes in the result
- like
Toru (alternative)
Both functions provided by this package can be replaced by utils provided by Toru 取る (dakujem/toru
),
which also offers tools to work with generic iterable
type.
The array_remap
can be replaced by less restrictive Itera::unfold
:
Pros:
- also enable to one value into multiple
- enable including branching logic (
if
) inside the mapper - may be more memory efficient, especially for large arrays
The array_map_keys
can be replaced by Itera::map
or Itera::apply
, because all callables in Toru receive keys along with values:
Pros:
- may be more memory efficient, especially for large arrays
array_remap
Allows re-mapping both indices and values of arrays using a mapper function.
Internally, this is a map-reduce operation.
See the source for more details.
array_map_keys
Allows to work with both array values and their indexes. The indexes are preserved in the result.
Note that one could natively call
array_map($values, array_keys($values))
, but that call does not preserve the original keys.
See the source for more details.
Why
These two fill the gap in PHP core for commonly occurring operations when the indexes are used during mapping.\ A seemingly simple task, it has its caveats when implementing, though.