Creates a Closure that takes the last N elements of an array or iterable. Terminal — the last N are only knowable once the source has been fully consumed.
/**
* @param int $count
* @return Closure(iterable<int|string, mixed>):mixed[]
* @throws \InvalidArgumentException if count is negative.
*/
Arrays\takeLast(int $count = 1): ClosureWhen Arrays\takeLast() 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.
$last3 = Arrays\takeLast(3);
print_r($last3([1, 2, 3, 4, 5])); // [3, 4, 5]