Tutorials Point


  Learning PHP
  Advanced PHP
  PHP Function Reference
  PHP Useful Resources
  Selected Reading

Copyright © 2014 by tutorialspoint



  Home     References     Discussion Forums     About TP  

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 Printer Friendly

Advertisements


  

Advertisements