array_shift in PHP

Syntax of array_shift

mixed array_shift(array stack)

Similar to array_pop(), but instead of removing and returning the last element in the array, it removes and returns the first element in the array. If the array is empty, or if the argument is not an array, returns NULL

Example of array_shift in PHP

<?php
$stack = array("orange", "banana", "apple", "raspberry");
$fruit = array_shift($stack);
print_r($stack);
?>
Array
(
    [0] => banana
    [1] => apple
    [2] => raspberry
)

Leave a Comment