Write a PHP program to get an array with n elements removed from the beginning of a given array
<?php //Licence: https://bit.ly/2CFA5XY function take($items, $n = 1) { return array_slice($items, 0, $n); } print_r(take([1, 2, 3], 1)); echo "\n"; print_r(take([1, 2, 3, 4, 5], 2)); ?>
Sample Output:
Array ( [0] => 1 ) Array ( [0] => 1 [1] => 2 )
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Sample Output:
Array ( [0] => 1 ) Array ( [0] => 1 [1] => 2 )need an explanation for this answer? contact us directly to get an explanation for this answer