Javatpoint Logo
Javatpoint Logo

PHP array_shift() function

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
)





Help Others, Please Share

facebook twitter pinterest