PHP code example of dragon-code / size-sorter

1. Go to this page and download the library: Download dragon-code/size-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/ */

    

dragon-code / size-sorter example snippets


use DragonCode\SizeSorter\Sorter;

return Sorter::sort(collect([
    'XXL',
    '26',
    '28',
    'XL',
    'ONE SIZE',
    'XXS',
    '2',
    '54',
]));

/*
 * Returns:
 * 
 * Collection([
 *   'XXS',
 *   'XL',
 *   'XXL',
 *   '2',
 *   '26',
 *   '28',
 *   '54',
 *   'ONE SIZE',
 * ])
 */

use DragonCode\SizeSorter\Sorter;

$items = Size::query()->get();

return Sorter::sort($items, 'title');

use DragonCode\SizeSorter\Enum\Group;
use DragonCode\SizeSorter\Sorter;

return Sorter::sort($items, groupsOrder: [3, 5, 4, 2, 1]);
// or
return Sorter::sort($items, groupsOrder: [Group::GROUP_3, Group::GROUP_5, Group::GROUP_4, Group::GROUP_2, Group::GROUP_1]);

use DragonCode\SizeSorter\Enum\Group;
use DragonCode\SizeSorter\Sorter;

return Sorter::sort($items, groupsOrder: [3, 5]);
// or
return Sorter::sort($items, groupsOrder: [Group::GROUP_3, Group::GROUP_5]);