Arrays\natsort()

transformer terminal accepts iterable returns Closure pure
() → (Iterable → string[])
At a glance — Natural-order sort. Keys preserved. Terminal.

Creates a Closure that sorts an array or iterable with a "natural order" algorithm — e.g. "img10" comes after "img2" instead of before it.

/**
  * @return Closure(iterable<int|string, mixed>):mixed[]
  */
Arrays\natsort(): Closure

Returned Closure

When Arrays\natsort() 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.

$nat = Arrays\natsort();
print_r($nat(['img10', 'img2', 'img1']));
// ['img1', 'img2', 'img10']

Details

Arrays Functions

Releated Array sort Functions