English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP array_shift() function usage and example

PHP Array Function Manual

The PHP array_shift() function removes the first element from the array

Syntax

array_shift ( $array );

Definition and Usage

array_shift() removes the first element from the array and returns it as a result, shortening the array by one element and moving all other elements up by one position. All numeric keys will be counted from zero, and text keys will remain unchanged.

Parameter

Serial NumberParameters and Description
1

array(Required)

It specifies an array.

Return value

It returns the first element of the array. If the array is empty (or not an array), it will return NULL.

Online example

This function removes the first value from the array and returns it, shortening the array by one element and moving all content down.

<?php 
   $input = array("a"=>"banana","b"=>"apple","c"=>"Mango");
   
   print_r(array_shift($input));
   print_r("\n");
   print_r(array_shift($input));
?>
Test and see‹/›

Output result:

banana
apple

PHP Array Function Manual