PHPackages                             dakujem/remapkeys - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. dakujem/remapkeys

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

dakujem/remapkeys
=================

Remap array keys.

1.0.1(3y ago)06.9k↓20%UnlicensePHPPHP &gt;=7.2CI passing

Since Apr 7Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/dakujem/remapkeys)[ Packagist](https://packagist.org/packages/dakujem/remapkeys)[ RSS](/packages/dakujem-remapkeys/feed)WikiDiscussions trunk Synced 1mo ago

READMEChangelog (2)Dependencies (1)Versions (3)Used By (0)

Remap Keys
==========

[](#remap-keys)

[![Tests](https://github.com/dakujem/remapkeys/actions/workflows/php-test.yml/badge.svg)](https://github.com/dakujem/remapkeys/actions/workflows/php-test.yml)[![Coverage Status](https://camo.githubusercontent.com/b9443d24bc9c86ab9e12b3ec767ead2df97497bfa6b431ef334e0d70d10b85db/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f64616b756a656d2f72656d61706b6579732f62616467652e7376673f6272616e63683d666561742f636f766572616c6c73)](https://coveralls.io/github/dakujem/remapkeys?branch=feat/coveralls)

> 💿 `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
- `array_map_keys`
    - like `array_map`, but passes indexes to the iteratee function and preserves indexes in the result

Toru (alternative)
------------------

[](#toru-alternative)

Both functions provided by this package can be replaced by utils provided by [Toru 取る (`dakujem/toru`)](https://github.com/dakujem/toru), which also offers tools to work with generic `iterable` type.

The `array_remap` can be replaced by less restrictive `Itera::unfold`:

```
// Original `array_remap` function call:
array_remap($function, $input);

// Replaced by `Itera` class method call:
Itera::unfold($input, $function);
```

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:

```
// Original `array_map_keys` function call:
array_map_keys($function, $input);

// Replaced by `Itera` class method call:
Itera::map($input, $function);
```

Pros:

- may be more memory efficient, especially for large arrays

`array_remap`
-------------

[](#array_remap)

Allows re-mapping both indices and values of arrays using a mapper function.

```
$input = [
    'foo' => 'bar',
    'b' => 'Bran',
    'unknown' => 'Stark',
];
array_remap(function($val, $index){
    return [ strtolower($val) => strlen($index) ];
}, $input);

/* result:
[
    'bar' => 3,
    'bran' => 1,
    'stark' => 7,
]
*/
```

```
$input = [
    [
        'url' => 'https://www.google.com',
        'provider' => 'Google'
    ],
    [
        'url' => 'https://www.yahoo.com',
        'provider' => 'Yahoo!'
    ],
];
array_remap(function($val){
    return [ $val['url'] => $val['provider'] ];
}, $input);

/* result:
[
    'https://www.google.com' => 'Google',
    'https://www.yahoo.com' => 'Yahoo!',
]
*/
```

> Internally, this is a map-reduce operation.

See [the source](/src/remap.php) for more details.

`array_map_keys`
----------------

[](#array_map_keys)

Allows to work with both array values and their indexes. The indexes are preserved in the result.

```
$input = [
    'foo' => 'bar',
    'boring' => 'Bran',
    'strange' => 'Stark',
];
array_map_keys(function($val, $index){
    return ucfirst($index) . ' ' . ucfirst($val);
}, $input);

/* result:
[
    'foo' => 'Foo Bar',
    'boring' => 'Boring Bran',
    'strange' => 'Strange Stark',
]
*/
```

> Note that one could natively call `array_map($values, array_keys($values))`, but that call does *not* preserve the original keys.

See [the source](/src/map.php) for more details.

Why
---

[](#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.

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance50

Moderate activity, may be stable

Popularity22

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~924 days

Total

2

Last Release

1308d ago

PHP version history (2 changes)1.0PHP &gt;=7

1.0.1PHP &gt;=7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/0bd7fa945013e9c0dcd65693575276bf5fcb9b9de13e1123e9f2c4a0a4c0fb6b?d=identicon)[dakujem](/maintainers/dakujem)

---

Top Contributors

[![dakujem](https://avatars.githubusercontent.com/u/443067?v=4)](https://github.com/dakujem "dakujem (9 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/dakujem-remapkeys/health.svg)

```
[![Health](https://phpackages.com/badges/dakujem-remapkeys/health.svg)](https://phpackages.com/packages/dakujem-remapkeys)
```

###  Alternatives

[spatie/laravel-multitenancy

Make your Laravel app usable by multiple tenants

1.3k2.9M16](/packages/spatie-laravel-multitenancy)[michelf/php-smartypants

PHP SmartyPants

1115.3M30](/packages/michelf-php-smartypants)[leocarmo/circuit-breaker-php

Circuit Breaker for PHP

300447.3k3](/packages/leocarmo-circuit-breaker-php)[riimu/kit-phpencoder

Highly customizable alternative to var\_export for PHP code generation

717.8M32](/packages/riimu-kit-phpencoder)[statamic/stringy

A string manipulation library with multibyte support, forked from @statamic

234.5M14](/packages/statamic-stringy)[kore/data-object

Simple base class for data objects.

111.2M7](/packages/kore-data-object)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
