PHP array_shift() function

PHP array_search() function
PHP array_slice() function

The array_shift function simply removes the first element of the array and returns its value.

If the array consists of numeric keys then after the removal of the first element by array_shift function, the rest of the keys get a new keys string from 0.

What is the syntax of the array_shift function in PHP?

array_shift(array)
ParameterDescription
arrayRequired. Specifies an array
array_shift function in PHP

Examples of array_shift function

<?php
$arr=array("a"=>"1","b"=>"2","c"=>"3");
echo array_shift($arr);
print_r($arr);
?>

In the above example, we remove the first element from the array using the array_shift function. It returns the value of the removed element.

<?php
$arr=array(0=>"R",1=>"G",2=>"B");
echo array_shift($arr);
print_r ($arr);
?>

In the above example, we use the array_shift function with the array having numeric keys. After the removal of the first element, the rest of the values will get new keys starting from 0.

PHP array_search() function
PHP array_slice() function
en English
X
Scroll to Top