title tags
tail
array,beginner

Returns all elements in an array except for the first one.

  • Use array_slice() and count() to return all the items in the array except for the first one.
function tail($items)
{
  return count($items) > 1 ? array_slice($items, 1) : $items;
}

tail([1, 2, 3]); // [2, 3]

Tags: PHP, PHP snippets, PHP function, PHP Method, tail, php array, array, array elements, count, array_slice