PHP code example of xtompie / sorter

1. Go to this page and download the library: Download xtompie/sorter library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

xtompie / sorter example snippets




tompie\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']],
        ],
    )
);