cable8mm / array-flatten
Flatten a multi-dimensional array in PHP.
v1.1.0
2026-06-27 18:54 UTC
Requires
- php: ^8.0.2
Requires (Dev)
- laravel/pint: ^1.0
- phpunit/phpunit: ^9.0|^10.0|^11.0|^12.0|^13.0
This package is auto-updated.
Last update: 2026-06-27 18:54:52 UTC
README
Normalize nested arrays.
array_flatten() returns a flat list from nested arrays and removes duplicate scalar values using strict comparison. For more information, please visit https://www.palgle.com/array-flatten/.
Why
To normalize nested arrays into a flat list while preserving first-seen order and strict uniqueness.
Installation
composer require cable8mm/array-flatten
Usage
use function Cable8mm\ArrayFlatten\array_flatten; array_flatten([1, [2, [3, [4, [5], 6], 7], 8], 9]); //=> [1, 2, 3, 4, 5, 6, 7, 8, 9]
Behavior
- Preserves first-seen order.
- Applies strict deduplication to scalar values.
- Traverses nested arrays at any depth.
License
The Array Flatten is open-sourced software licensed under the MIT license.