title | tags |
---|---|
drop
|
array,beginner
|
Returns a new array with $n
elements removed from the left.
- Use
array_slice()
to remove$n
elements from the left. - Omit the second argument,
$n
, to only remove one element.
function drop($items, $n = 1)
{
return array_slice($items, $n);
}
drop([1, 2, 3]); // [2,3]
drop([1, 2, 3], 2); // [3]
Tags: PHP, PHP function, remove elements, remove from array, php Array, Array