Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/amsoell/laravel-collection-normalize-keys
Laravel collection macro that ensures all elements contain the same keys
https://github.com/amsoell/laravel-collection-normalize-keys
Last synced: about 2 months ago
JSON representation
Laravel collection macro that ensures all elements contain the same keys
- Host: GitHub
- URL: https://github.com/amsoell/laravel-collection-normalize-keys
- Owner: amsoell
- Created: 2018-03-13T21:07:31.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-09-13T10:10:30.000Z (over 6 years ago)
- Last Synced: 2024-12-01T07:33:14.931Z (about 2 months ago)
- Language: PHP
- Homepage:
- Size: 1.95 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Laravel normalizeKeys collection method
Ensure that every array / collection within a collection contains the same keys
```php
$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`