https://github.com/xtompie/lasorter
https://github.com/xtompie/lasorter
Last synced: 5 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/xtompie/lasorter
- Owner: xtompie
- Created: 2021-04-28T21:24:04.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-04-28T21:24:49.000Z (about 5 years ago)
- Last Synced: 2023-07-16T07:17:22.966Z (about 3 years ago)
- Language: PHP
- Size: 1000 Bytes
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Sorter
Laravel collection macro sorter for sort multidimensional array by multiple criteria like columns, keys, any deep value
## Installation
```bash
composer require xtompie/lasorter
```
## Usage
```php
['city' => 'Warszawa', 'street' => 'Lea', 'meta' => (object)['priority' => '5']],
'b' => ['city' => 'Krakow', 'street' => 'Lea', 'meta' => (object)['priority' => '10']],
'c' => ['city' => 'Krakow', 'street' => 'Krolewska', 'meta' => (object)['priority' => '10']],
'd' => ['city' => 'Krakow', 'street' => 'Lea', 'meta' => (object)['priority' => '10']],
])
->sorter(function(Sorter $sorter) {
return $sorter
->asc("city")
->asc("street")
->asc(fn($i) => $i['meta']->priority)
->desc(fn($i, $k) => $k)
;
})
);
```