1<?php
2$stack = array("orange", "banana", "apple", "raspberry");
3$fruit = array_shift($stack);
4print_r($stack);
5?>
6
7
8// Array
9// (
10// [0] => banana
11// [1] => apple
12// [2] => raspberry
13// )
1array_shift — Shift an element off the beginning of array
2
3array_shift($array) shifts the first value of the array off and returns it,
4shortening the array by one element and moving everything down. All numerical
5array keys will be modified to start counting from zero while literal keys
6won't be affected.
1<?php
2$a=array("a"=>"red","b"=>"green","c"=>"blue");
3echo array_shift($a);
4print_r ($a);
5?>
6
7The array_shift() function removes the first element from an array, and returns the value of the removed element.
8
9Note: If the keys are numeric, all elements will get new keys, starting from 0 and increases by 1 (See example below).
10
11