Creates a Closure that sorts an array or iterable by value using a custom comparator, preserving keys.
/**
* @param callable(mixed $a, mixed $b): int $function
* @return Closure(iterable<int|string, mixed>):mixed[]
*/
Arrays\uasort(callable $function): ClosureWhen Arrays\uasort() 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): arrayThis can be used to create a simple closure which can be used as a regular function.
$byAuthor = Arrays\uasort(fn($a, $b) => strcmp($a['author'], $b['author']));
$books = [
'bk1' => ['author' => 'Carter'],
'bk2' => ['author' => 'Adams'],
'bk3' => ['author' => 'Baker'],
];
print_r($byAuthor($books));
// ['bk2' => ..., 'bk3' => ..., 'bk1' => ...]