cable8mm/array-flatten
Flatten nested arrays into a single-level array with this lightweight PHP utility. It recursively walks multidimensional arrays and returns a clean, flat list of values, making it handy for processing config, request data, or deeply nested structures in Laravel projects.
Since there is no prior assessment, this is a fresh evaluation of cable8mm/array-flatten at v1.1.0.
Install via Composer:
composer require cable8mm/array-flatten
The package exposes a simple helper to flatten nested arrays into a single-level array (mirroring Laravel's Arr::flatten() behavior but without needing to import the framework helper). Start by checking:
README.md for the exact public API and example callssrc/ for the primary flattening class/traittests/ (rewritten in v1.1.0) as executable documentation of supported inputsFirst use case: you have a deeply nested array of IDs/attributes (e.g., from a nested request payload or a grouped query result) and need a flat list for validation, unique checks, or DB whereIn. Replace hand-rolled recursive loops with:
use Cable8mm\ArrayFlatten\...; // see README for exact namespace
$flat = flatten([1, [2, 3, [4, 5]]]); // [1, 2, 3, 4, 5]
Validator::make(), so rules like array, distinct, and in: apply uniformly across dimensions.collect(...) and chain ->unique()->values() for a compact dedupe-then-fetch pattern feeding Model::whereIn().groupBy() outputs when aggregating labels, pivot IDs, or tag lists for serialization.Arr::flatten() does not preserve keys). If you depend on keys, wrap with array_values() explicitly or a custom recurse.is_iterable will iterate over ArrayAccess objects; if you only want arrays, confirm behavior for Collection and Traversable inputs.xdebug.max_nesting_level if running tests locally.^1.0 if you want the fixes without surprise, or 1.1.* if you want the refactored internals.array_filter(flatten($x)) over forking — the package intentionally does one thing.How can I help you explore Laravel packages today?