• PHP Video Tutorials

PHP - Function array_shift()



Syntax

array_shift ( $array );

Definition and Usage

This function shifts the first value of the array off and returns it, shortening the array by one element and moving everything down.

Parameters

Sr.No Parameter & Description
1

array(Required)

It specifies an array.

Return Values

It returns first element of the array and if array is empty (or is not an array), NULL will be returned.

Example

Try out following example −

<?php 
   $input = array("a"=>"banana","b"=>"apple","c"=>"Mango");
   
   print_r(array_shift($input));
   print_r("\n");
   print_r(array_shift($input));
?> 

This will produce the following result −

banana
apple
php_function_reference.htm
Advertisements