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

Basic PHP Tutorial

Advanced PHP 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

The array_shift() function removes the first element from the array and returns it, shortening the array by one element and moving all other elements forward. 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 other 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