kaiseki / nested-array
Recursively merge nested arrays (deep merge).
1.0.0
2026-05-29 09:40 UTC
Requires
- php: ^8.2
Requires (Dev)
- bnf/phpstan-psr-container: ^1.1
- kaiseki/php-coding-standard: ^1.0
- maglnet/composer-require-checker: ^4.0
- phpstan/extension-installer: ^1.4
- phpstan/phpstan: ^2.0
- phpstan/phpstan-phpunit: ^2.0
- phpstan/phpstan-strict-rules: ^2.0
- phpunit/phpunit: ^11.0
- roave/security-advisories: dev-latest
This package is auto-updated.
Last update: 2026-06-02 23:44:46 UTC
README
Recursively merge nested arrays — a small, dependency-free deep-merge utility.
String keys are merged recursively (nested arrays are combined rather than replaced), while integer-keyed values are appended. This makes it well suited to merging layered configuration, where later sources override earlier ones but lists accumulate.
Installation
composer require kaiseki/nested-array
Requires PHP 8.2 or newer.
Usage
use Kaiseki\Utility\NestedArray; $merger = new NestedArray(); $result = $merger->mergeDeep( [ 'db' => ['host' => 'localhost', 'port' => 3306], 'plugins' => ['seo'], ], [ 'db' => ['port' => 5432], 'plugins' => ['cache'], ], ); // [ // 'db' => ['host' => 'localhost', 'port' => 5432], // 'plugins' => ['seo', 'cache'], // ]
mergeDeep() accepts any number of arrays and merges them left to right.
Merge rules
- String key, array value — merged recursively.
- String key, scalar value — the value from the last array wins.
- Integer key — appended, so sequential/list arrays are concatenated rather than merged by index.
Development
composer install
composer check # check-deps, cs-check, phpstan
License
MIT — see LICENSE.