Sort an array by a callback function that compares two values at a time and returns the sorted array.

array:sort_by_function(ARRAY $array, $comparision_function) : ARRAY

$unsorted_array = [3, 1, 2]
$sorted_array = array:sort_by_function($unsorted_array, ƒ($a, $b){
    IF($a === $b) {
        RETURN 0
    }
    IF($a < $b) {
        RETURN -1
    } ELSE {
        RETURN 1
    }
})

$sorted_array
#=> [
#=>     1,
#=>     2,
#=>     3
#=> ]

Copyright ©2013-2022 SunSed®. All rights reserved.