Looking to hire Laravel developers? Try LaraJobs

laravel-collection-normalize-keys maintained by amsoell

Description
Laravel collection macro to ensure consistent keys within a multidimensional collection
Author
Last update
2018/09/13 12:10 (dev-master)
License
Links
Downloads
18

Comments
comments powered by Disqus

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