PHP code example of xtompie / lasorter

1. Go to this page and download the library: Download xtompie/lasorter 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 / lasorter example snippets




tompie\Sorter\Sorter;

print_r(
    collect([
        'a' => ['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)
            ;
        })
);