xtompie / sorter
Sort multidimensional array by multiple criteria like array values, object properties, any deep value
2.0.1
2022-05-22 13:54 UTC
Requires
- php: ^8.0
Requires (Dev)
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2026-02-22 22:21:54 UTC
README
Sort multidimensional array by multiple criteria like array values, object properties, any deep value.
Installation
composer require xtompie/sorter
Usage
<?php require 'vendor/autoload.php'; use Xtompie\Sorter\Sort; use Xtompie\Sorter\Sorter; print_r( (new Sorter())( [ Sort::ofKey('city'), Sort::ofKey('street', SORT_DESC), Sort::of(fn($i) => $i['meta']->priority), ], [ ['city' => 'Warszawa', 'street' => 'Lea', 'meta' => (object)['priority' => '5']], ['city' => 'Krakow', 'street' => 'Lea', 'meta' => (object)['priority' => '10']], ['city' => 'Krakow', 'street' => 'Krolewska', 'meta' => (object)['priority' => '10']], ['city' => 'Krakow', 'street' => 'Lea', 'meta' => (object)['priority' => '5']], ], ) );