Arrays\tail()

transformer lazy accepts iterable returns value pure
Iterable → Iterable | null
At a glance — Direct call — not a Closure constructor. For Generators it streams lazily; for arrays it returns a new array (or null when empty).

Returns the remainder of an array or iterable after the first element has been removed. An array returns either a new array (or null if empty). A Generator returns a Generator that lazily yields every element after the first; an empty Generator source yields an empty Generator, not null.

/**
  * @param iterable<int|string, mixed> $source
  * @return array<int|string, mixed>|\Generator<int|string, mixed>|null
  */
Arrays\tail(iterable $source)

Examples

Partial Application

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

var_dump(Arrays\tail(['a', 'b', 'c'])); // ['b', 'c']
var_dump(Arrays\tail(['only']));        // []
var_dump(Arrays\tail([]));              // NULL

Works with Iterables & Generators

Accepts a Generator or any Traversable as input.

$gen = (function () { yield 'a'; yield 'b'; yield 'c'; })();
foreach (Arrays\tail($gen) as $v) echo $v; // bc

Details

Arrays Functions

Releated Array access Functions