array_sortby
Description
Sorts elements in an array according to the ascending order of elements in another array or array converted from a lambda expression. For more information, see Lambda expression. This function is supported from v2.5.
Elements in the two arrays are like key-value pairs. For example, b = [7,5,6] is the sorting key of a = [3,1,4]. According to the key-value pair relationship, elements in the two arrays have the following one-to-one mapping.
Array | Element 1 | Element 2 | Element 3 |
---|---|---|---|
a | 3 | 1 | 4 |
b | 7 | 5 | 6 |
After array b
is sorted in ascending order, it becomes [5,6,7]. Array a
becomes [1,4,3] accordingly.
Array | Element 1 | Element 2 | Element 3 |
---|---|---|---|
a | 1 | 4 | 3 |
b | 5 | 6 | 7 |
Syntax
array_sortby(array0, array1)
array_sortby(<lambda function>, array0 [, array1...])
-
array_sortby(array0, array1)
Sorts
array0
according to the ascending order ofarray1
. -
array_sortby(<lambda function>, array0 [, array1...])
Sorts
array0
according to the array returned from the lambda function.
Parameters
array0
: the array you want to sort. It must be an array, array expression, ornull
. Elements in the array must be sortable.array1
: the sorting array used to sortarray0
. It must be an array, array expression, ornull
.lambda function
: the lambda expression used to generate the sorting array.
Return value
Returns an array.