In this tutorial we will learn how to remove first element of an array using PHP, we can use PHP array_shift() function to remove first value or element of an array.
Table of Contents
PHP array_shift() function
PHP array_shift() function removes the first element of array and returns the first value as a result.
We can also use array_shift() function to get first value of array.
array_shift() function returns NULL if array is empty.
<?php
$array = array("HTML", "CSS", "JavaScript", "PHP");
print_r($array);
echo "<br />";
$firstElement = array_shift($array);
print_r($array); // array without first element
?>
The above code will remove the first element of array.