Copyright © tutorialspoint.com

PHP Function array_shift()

previous
Advertisements

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. All numerical array keys will be modified to start counting from zero while literal keys won't be touched.

Paramters

ParameterDescription
arrayRequired. Specifies an array.

Return Values

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
$array=array("a"=>"banana","b"=>"apple","c"=>"orange");

print_r(array_shift($array));
print_r("<br />");
print_r(array_shift($array));
?> 

This will produce following result:

banana
apple
previous

Copyright © tutorialspoint.com