Skip to content

Latest commit

 

History

History
33 lines (24 loc) · 622 Bytes

File metadata and controls

33 lines (24 loc) · 622 Bytes

sort

Description

Sorts a collection using a comparator function

Parameters

fn
Function to compare a couple of elements between them.
coll
Collection of values to be sorted.

Examples

Sort in ascending order a collection:

<?php

use function Lambdish\Phunctional\sort;

return sort(
    function ($one, $other) {
        return $one === $other ? 0 : ($one > $other ? 1 : -1);
        // In PHP 7 you can use the spaceship operator: $one <=> $other
    }, 
    [9, 1, 2, 3, 4, 1, 5, 6, 7, 4, 9, 8]
);

// [1, 1, 2, 3, 4, 4, 5, 6, 7, 8, 9, 9]