PHP array_shift() Function Example

PHP Script:

$stack = array("orange", "banana", "apple", "raspberry");
$fruit = array_shift($stack);
echo "<br />";


[0] => banana
[1] => apple
[2] => raspberry


PHP array_shift() function shifts off/pops the first/top value of the array and returns it, reducing the array by one element and moving everything down. The numeric key will be re-assigned starting from zero, while the literal keys would remain unchanged.
This method resets the array pointer of the input array after use.

PHP array_shift function parameters:

1- array: The array to be shifted.

PHP array_shift function output:

1- mixed: Returns the shifted value, or NULL if array is empty or it is not an array, where shifted value can itself be an array.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s