X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY ANGULAR BOOTSTRAP XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

PHP array_shift() Function

PHP Array Reference PHP Array Reference

Example

Remove the first element (red) from an array, and return the value of the removed element:

<?php
$a=array("a"=>"red","b"=>"green","c"=>"blue");
echo array_shift($a);
print_r ($a);
?>

Run example »

Definition and Usage

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

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


Syntax

array_shift(array)

Parameter Description
array Required. Specifies an array

Technical Details

Return Value: Returns the value of the removed element from an array, or NULL if the array is empty
PHP Version: 4+


More Examples

Example 1

Using numeric keys:

<?php
$a=array(0=>"red",1=>"green",2=>"blue");
echo array_shift($a);
print_r ($a);
?>

Run example »


PHP Array Reference PHP Array Reference

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB HOSTING

UK Reseller Hosting

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE

facebook