Skip to main content

argsort

argsort(
@x ## llll (required)
@function null
) -> llll

Returns the indices that would sort an input llll in ascending order. Instead of returning a sorted version of the llll, it provides an index permutation that, when applied to the original llll, results in a sorted sequence.


Arguments

  • @x [llll]: llll to sort. (required)
  • @function [function]: Optional lambda sorting function. (default: null).

Output

Sorted indices [llll]


Usage

$nums = 44 11 33 22;
$order = argsort($nums);
print($order); ## 2 4 3 1
print($nums:[$order]) ## 11 22 33 44