PHP array_shift() Function
PHP array_shift() Function
The array_shift() in PHP shifts the first value of the array off. This function returns the same value after shortening the array by one element and moving everything.
Syntax
array_shift ( array &$array )
Parameter
array(required)- This parameter represents the input array
Return
This function returns the shifted value or returns NULL if the specified array is empty or is not an array.
Example 1
Output
New Array: Array ( [0] => orange [1] => banana [2] => apple [3] => raspberry ) The shifted array is orange Shifted Array: Array ( [0] => banana [1] => apple [2] => raspberry )
Example 2
Output
405 Array ( [0] => 5 [1] => 1 [2] => 22 [3] => 22 [4] => 10 [5] => 10 )
Example 3
Output
Element Shifted: 405 Element Shifted: 5 Element Shifted: 1 Element Shifted: 22 Element Shifted: 22 Array ( [0] => 10 [1] => 10 )
Example 4
Output
New Array: Array ( [0] => ) The shifted array is Shifted Array: Array ( )