amsoell/laravel-collection-normalize-keys

Laravel collection macro to ensure consistent keys within a multidimensional collection

Installs: 18

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

pkg:composer/amsoell/laravel-collection-normalize-keys

v1.0 2018-03-13 21:22 UTC

This package is auto-updated.

Last update: 2025-09-14 03:51:50 UTC


README

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