Q:

Write a PHP program to create a new array with n elements removed from the left

0

Write a PHP program to create a new array with n elements removed from the left

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

<?php
function drop_from_left($items, $n = 1)
{
    return array_slice($items, $n);
}
print_r(drop_from_left([1, 2, 3])); 
print_r(drop_from_left([1, 2, 3, 4], 2));

?>

Sample Output:

Array
(
    [0] => 2
    [1] => 3
)
Array
(
    [0] => 3
    [1] => 4
)

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now