In this tutorial, you shall learn how to remove first element in given array in PHP using unset() function, with the help of example programs.

PHP – Remove first element in array

To remove first element in array in PHP, we can use unset() function.

The expression to remove the first element in array arr is

</>
Copy
unset( $arr[0] )

index=0 represents the first element in the array.

Example

In this example, we take an array arr with some elements. We remove the first element in the array using unset() function.

PHP Program

</>
Copy
<?php
  $arr = ["apple", "banana", "cherry"];
  unset($arr[0]);
  print_r($arr);
?>

Output

PHP - Remove first element in array

Conclusion

In this PHP Tutorial, we learned how to remove the first element in array using unset() function.