English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The PHP array_shift() function removes the first element from the array
array_shift($array);
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.
Serial Number | Parameters and Description |
---|---|
1 | array(Required) It specifies an array. |
It returns the first element of the array. If the array is empty (or not an array), it will return NULL.
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