Remove the first element (e.g., “red”) from an array and return the value of the removed element.
<?php $a=array(“a”=>“red”,“b”=>“green”,“c”=>“blue”); echo array_shift($a); print_r ($a); ?> |
The array_shift() function removes the first element from an array and returns its value.
Note: If the array has numeric keys, all remaining elements will be reindexed, starting from 0 and increasing by 1 (see example below).
array_shift(array) |
Parameter |
Description |
array |
Required. Specifies the array to modify. |
Return Value: |
Returns the value of the removed element from an array, or NULL if the array is empty |
PHP Version: |
4+ |
With numeric keys:
<?php $a=array(0=>“red”,1=>“green”,2=>“blue”); echo array_shift($a); print_r ($a); ?> |