In this tutorial, you will learn how to delete the first element from an indexed array in PHP.
In PHP, there is a predefined function array_shift(), which will help us to delete the first element from an array.
Here is an example for deleting the first element from an array $a.
<html> <body> <?php $a=array("shilu","tarak","mona","rajat"); array_shift(); for($i=0;$i<count($a);$i=$i+1) { echo $a[$i]."<br>"; } ?> </body> </html>
Output:
tarak mona rajat
Here the array $a is containing 4 elements. The first element is deleted using the function array_shift().
After deleting the first array element from the array, the present array elements are:
Here $a[0]="tarak"=first array element value. $a[1]="mona"=second array element value. $a[2]="rajat"=third array element value.
Finally, we have printed the array element values with different lines using for loop and echoed statement and <br> tag.