PHP array_shift () function
Examples
Remove the first element in the array (red), and returns the removed element:
$a = array ( " a " => " red " , " b " => " green " , " c " => " blue " ) ;
echo array_shift ( $a ) ;
print_r ( $a ) ;
Running instance »
Definition and Usage
array_shift () function is used to delete the first element in the array, and returns the removed element.
Note: If a key is digital, all elements will get a new key name, starting with 0 and increments by 1 (see examples below).
grammar
array_shift( array )
参数 | 描述 |
---|---|
array | 必需。规定数组。 |
technical details
return value: | Returns removed from the array element's value, if the array is empty, returns NULL. |
---|---|
PHP version: | 4+ |
More examples
Example 1
Use the numeric keys:
<?php
$a=array(0=>"red",1=>"green",2=>"blue");
echo array_shift($a);
print_r ($a);
?>
$a=array(0=>"red",1=>"green",2=>"blue");
echo array_shift($a);
print_r ($a);
?>
Running instance »
Complete PHP Array Reference