Sorts a collection using a comparator function
- fn
- Function to compare a couple of elements between them.
- coll
- Collection of values to be sorted.
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]