array_shift
Move the cell at the beginning of the array out of the array
array_shift()
function deletes the first element in the array and returns the value of the deleted element.
Note: If the key name is numeric, all elements will get a new key name, starting at 0 and incrementing with 1 (see the example below).
Delete the first element (red) in the array and return the value of the deleted element:
<?php $a = array ( "a" => "red" , "b" => "green" , "c" => "blue" ) ; echo array_shift ( $a ) ; print_r ( $a ) ; ?>
Try it yourself
Use the numeric key name:
<?php $a = array ( 0 => "red" , 1 => "green" , 2 => "blue" ) ; echo array_shift ( $a ) ; print_r ( $a ) ; ?>
Try it yourself
array_shift ( array )
parameter | describe |
---|---|
array | Required. Specify array. |