LaravelPackages.net
Acme Inc.
Toggle sidebar
amsoell/laravel-collection-normalize-keys

Laravel collection macro to ensure consistent keys within a multidimensional collection

18
0
v1.0
About amsoell/laravel-collection-normalize-keys

amsoell/laravel-collection-normalize-keys is a Laravel package for laravel collection macro to ensure consistent keys within a multidimensional collection. It currently has 0 GitHub stars and 18 downloads on Packagist (latest version v1.0). Install it with composer require amsoell/laravel-collection-normalize-keys. Discover more Laravel packages by amsoell or browse all Laravel packages to compare alternatives.

Last updated

Laravel normalizeKeys collection method

Ensure that every array / collection within a collection contains the same keys

$collection = collect([
  [ 'a' => 1, 'b' => 2],
  [ 'a' => 1, 'c' => 3],
  [ 'b' => 1, 'c' => 3],
]);

$collection->normalizeKeys();

// [
//     [ 'a' => 1, 'b' => 2, 'c' => null ],
//     [ 'a' => 1, 'b' => null, 'c' => 3 ],
//     [ 'a' => null, 'b' => 1, 'c' => 3 ],
// ];

Installation

composer require amsoell/laravel-collection-normalize-keys

Star History Chart