PHP array_shift() Function
Last Updated : 17 Mar 2025
The array_shift() function is an inbuilt function of PHP. The array_shift( ) function is used to remove the first element from an array, and returns the value of the removed element. This function was introduced in PHP 4.0.
Syntax
Parameter
| Parameter | Description | Is compulsory |
|---|---|---|
| array name | The specified array. | compulsory |
Return type
The array_shift( ) function returns the value of the removed element from an array. If the array is empty, it will return NULL.
Important note: If the keys are numeric, all elements will get new keys, starting from 0 and increases by 1.
Example 1
Output:
testArray
(
[0] => one day
[1] => t20
)
Example 2
Output:
Array
(
[0] => math
[1] =>english
[2] =>hindi
)
Science
Example 3
Output:
200Array
(
[sehwag] => 400
[ganguly] => 500
[yuvraj] => 100
)
Example 4
Output:
TCSArray
(
[0] => Infosys
[1] =>Mindtree
)
Next TopicPhp-array-shuffle-function