PHP code example of alebediev / sorter
1. Go to this page and download the library: Download alebediev/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/ */
alebediev / sorter example snippets
...
use Alebediev\Sorter\Sorter;
use Alebediev\Sorter\Strategy\ScalarType\DescendingSorter;
use Alebediev\Sorter\Strategy\ScalarType\AscendingSorter;
use Alebediev\Sorter\Strategy\NullSorter;
...
$descSorter = new Sorter(new DescendingSorter());
$ascSorter = new Sorter(new AscendingSorter());
$nullSorter = new Sorter(new NullSorter());
$descSortedArray = $descSorter->sort($sortableArray);
$ascSortedArray = $ascSorter->sort($sortableArray);
// NullSorter
$array = $nullSorter->sort($sortableArray);
// for change sorting strategy
$someTestArray = $descSorter->changeStrategy(new NullSorter())->sort($sortableArray);