03-Apr-2023
.
Admin
Hi Dev,
This tutorial will give you simple example how to array remove first an elements in php. you will learn remove first n element in array php with code examples. Follow bellow tutorial step remove first n specific element from array. this example will help you use the only keep the first n elements of an array in php. You just need to some step to done array_shift function user remove first n elements in php.
Example 1:
index.php
<?php
$game = array(1 => "Cricket", 2 => "Chess", 3 => "Ludo");
echo "Removed element: ".array_shift($game). "</br>";
print_r($game);
?>
Output:
Removed element: Cricket
Array ( [0] => Chess [1] => Ludo )
Example 2:
index.php
<?php
$a = array("red","green","blue","yellow","brown");
print_r(array_slice($a,1));
?>
Output:
Array ( [0] => green [1] => blue [2] => yellow [3] => brown )
I hope it could help you...
#PHP