PHPackages                             germanovs/php-keys-mover - 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. germanovs/php-keys-mover

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

germanovs/php-keys-mover
========================

Allows you to change keys positions in arrays

v1.0.0(3y ago)04[5 issues](https://github.com/germanovs/php-keys-mover/issues)MITPHP

Since Sep 24Pushed 3y ago1 watchersCompare

[ Source](https://github.com/germanovs/php-keys-mover)[ Packagist](https://packagist.org/packages/germanovs/php-keys-mover)[ RSS](/packages/germanovs-php-keys-mover/feed)WikiDiscussions master Synced 1mo ago

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

PHP Keys Mover
==============

[](#php-keys-mover)

Purpose
-------

[](#purpose)

This class is intended to change keys order in associative arrays with one line of code.

Installation
------------

[](#installation)

```
composer require germanovs/php-keys-mover

```

Properties
----------

[](#properties)

`string $message`Contains information about last operation. You can read this to find what excatly went wrong, if any methods returned false.

Methods
-------

[](#methods)

`move(array &$array, string|integer $key, string|integer $where): bool`

- Moves `$key` in `$where` position inside `$array`.
- `$key` and `$where` and can be string as key or integer as index.
- Modifies source array directly.
- Returns `true` on success and `false` on failure.

#### Usage

[](#usage)

```
$keyMover = new KeysMover\KeysMover();
$array = [
    'one' => 1,
    'two' => 2,
    'three' => 3
];
```

```
$keyMover->move($array, 'one', 'two');
/*
result:
[
    'two' => 2,
    'one' => 1,
    'three' => 3
]
*/
```

```
$keyMover->move($array, 'two', 2);
/*
result:
[
    'one' => 1,
    'three' => 3,
    'two' => 2
]
*/
```

Future plans
------------

[](#future-plans)

These methods will be available in future versions

- `shift(array &$array, string|integer $key, integer $shift): bool`Moves `$key` by `$shift` positions Ex: `$keysMover->shift($array, 'three', -2);`
- `moveAfter(array &$array, string|integer $key, string|integer $target): bool`Puts `$key` after `$target`Ex: `$keysMover->moveAfter($array, 'three', 'one');`
- `moveBefore(array &$array, string|integer $key, string|integer $target): bool`Puts `$key` before `$target`Ex: `$keysMover->moveAfter($array, 'three', 'two');`
- `rearrange(array &$array, array $order): bool`Rearranges keys in `$array`, using `$order` as pattern Ex: `$keysMover->rearrange($array, ['two', 'three', 'one']);`

Methods `move()` and `shift()` will get `bool $swap = false` argument. This will alow to move replaced key to initial position of moved key.

Please, feel free to open a discussion with your feedback, thoughts, feature proposals etc.

License
-------

[](#license)

MIT

**Free Software, Hell Yeah!**

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

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

Unknown

Total

1

Last Release

1323d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/298360504a5409fff9b4b3510e81901dead6b62611a78ef13e2795691a70b973?d=identicon)[germanovs](/maintainers/germanovs)

---

Top Contributors

[![germanovs](https://avatars.githubusercontent.com/u/56565712?v=4)](https://github.com/germanovs "germanovs (1 commits)")

---

Tags

phparraykeyarrayskeysmove

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/germanovs-php-keys-mover/health.svg)

```
[![Health](https://phpackages.com/badges/germanovs-php-keys-mover/health.svg)](https://phpackages.com/packages/germanovs-php-keys-mover)
```

###  Alternatives

[dotty/dotty

Easy access to array data using dot notation

1293.7k1](/packages/dotty-dotty)

PHPackages © 2026

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