PHP code example of sebastiansulinski / sorter

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

    

sebastiansulinski / sorter example snippets


$array = [
    [
        'name' => 'Arthur'
    ],
    [
        'name' => 'Tom'
    ],
    [
        'name' => 'Mark'
    ]
];

$sorter = new Sorter($array);

// sort the array by 'name' key
$sorter->asc('name');

// two ways of printing array
echo $sorter->printR();
echo $sorter;

// get resulting, previously sorted array
$array_sorted_asc = $sorter->collection();

// reverse order and return the resulting array
$array_sorted_desc = $sorter->desc('name')->collection();