Using The Array_Remove() Function To Remove Several Elements From The Beginning And The End Of An Array:

<?php
$languages = array( 'French', 'German', 'Russian', 'Chinese');
printf("<p>Original array:\n%s</p>\n", var_export($languages, TRUE)); $num = 2;
$removed1 = array_remove($languages, 0, $num);
$removed2 = array_remove($languages, count($languages) - $num, $num);
printf("<p>Removed (start): %s<br />Removed (end): %s<br /> Remaining: %s</p>\n", var_export($removed1, TRUE), var_export($removed2, TRUE), var_export($languages, TRUE));
?>

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.