Php Array Element Shift Function

What is array_shift Function?

Explanation

The "array_shift" function is used to shift an element off the beginning of an array.

Syntax:


array_shift(array)

In the above syntax "array" specifies the array from which an element is to be removed from the begining.

Example :


<?php
$b=array("c"=>"Cherry","b"=>"Strawberry");
print_r(array_shift($b));
?>
Result :

Array ([b]=>Strawberry)

In the above example first element that is "Cherry" is removed and the rest is displayed.

PHP Topics


Ask Questions

Ask Question