PHP array_shift() Function


Complete PHP Array Reference

Definition and Usage

The array_shift() function removes the first element from an array, and returns the value of the removed element.

Syntax

array_shift(array)

Parameter Description
array Required. Specifies an array


Tips and Notes

Note: If the keys are numeric, all elements will get new keys, starting from 0 and increases by 1. (See Example)

Example

<?php
$a=array("a"=>"Dog","b"=>"Cat","c"=>"Horse");
echo array_shift($a);
print_r ($a);
?>

The output of the code above will be:

Dog
Array ( [b] => Cat [c] => Horse )


Example

With numeric keys:

<?php
$a=array(0=>"Dog",1=>"Cat",2=>"Horse");
echo array_shift($a);
print_r ($a);
?>

The output of the code above will be:

Dog
Array ( [0] => Cat [1] => Horse )


Complete PHP Array Reference
Have Any Suggestion? We Are Waiting To Hear from YOU!

Your Query was successfully sent!