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
  • Use user-defined comparison functions to sort key names in an array uksort

    uksort

    Useuser-definedcompa
  • Sort arrays by key names ksort

    ksort

    Sortarraysbykeynames
  • Insert one or more units at the beginning of an array array_unshift

    array_unshift

    Insertoneormoreunits
  • Sort arrays sort

    sort

    Sortarrays
  • Calculate the number of units in an array, or the number of attributes in an object count

    count

    Calculatethenumberof
  • Point the inner pointer of the array to the last unit end

    end

    Pointtheinnerpointer
  • Create an array based on range, containing specified elements range

    range

    Createanarraybasedon
  • Move the cell at the beginning of the array out of the array array_shift

    array_shift

    Movethecellatthebegi
Popular Articles