Current Location: Home> Function Categories> array_shift

array_shift

Move the cell at the beginning of the array out of the array
Name:array_shift
Category:Array
Programming Language:php
One-line Description:Delete the first element in the array and return the value of the deleted element.

Definition and usage

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).

Example

Example 1

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

Example 2

Use the numeric key name:

 <?php
$a = array ( 0 => "red" , 1 => "green" , 2 => "blue" ) ;
echo array_shift ( $a ) ;
print_r ( $a ) ;
?>

Try it yourself

grammar

 array_shift ( array )
parameter describe
array Required. Specify array.
Similar Functions
Popular Articles