Arrays\krsort()

transformer terminal accepts iterable returns Closure pure
int → (Iterable → T[])
At a glance — Reverse key sort. Keys preserved. Terminal.

Creates a Closure that sorts an array or iterable by key in descending order, preserving key-value associations.

/**
  * @param int $flag PHP sort flag constant.
  * @return Closure(iterable<int|string, mixed>):mixed[]
  */
Arrays\krsort(int $flag = SORT_REGULAR): Closure

Returned Closure

When Arrays\krsort() is called, it returns the following Closure which can be used like a regular function.

/**
  * @param iterable<int|string, mixed> $source
  * @return mixed[]
  */
$function (iterable $source): array

Examples

Partial Application

This can be used to create a simple closure which can be used as a regular function.

$byKeyDesc = Arrays\krsort();
print_r($byKeyDesc(['a' => 1, 'b' => 2]));
// ['b' => 2, 'a' => 1]

Details

Arrays Functions

Releated Array sort Functions