Removing the First Element of an Array in PHP


Use array_shift() to remove and return the first element of an array, shifting all other elements down.

Source Code

$numbers = [1, 2, 3, 4, 5];
$firstNumber = array_shift($numbers);
echo $firstNumber; // Outputs: 1
print_r($numbers); // Remaining array
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments