PHP array_shift() Function
Complete PHP Array Reference
Definition and Usage
The array_shift() function removes the first element from an array, and returns the value
of the removed element.
Syntax
| Parameter |
Description |
| array |
Required. Specifies an array |
Tips and Notes
Note: If the keys are numeric, all elements will get new keys, starting from 0 and increases by 1.
(See example 2)
Example 1
<?php
$a=array("a"=>"Dog","b"=>"Cat","c"=>"Horse");
echo array_shift($a);
print_r ($a);
?>
|
The output of the code above will be:
Dog
Array ( [b] => Cat [c] => Horse )
|
Example 2
With numeric keys:
<?php
$a=array(0=>"Dog",1=>"Cat",2=>"Horse");
echo array_shift($a);
print_r ($a);
?>
|
The output of the code above will be:
Dog
Array ( [0] => Cat [1] => Horse )
|
Complete PHP Array Reference
NEW! Altova MissionKit 2007– Save ½ off Intelligent tools for XML developers & software architects
 | |
The Altova MissionKit 2007
bundles Altova’s application development, data management and
modeling tools at 50% off their regular prices. It is available in a
variety of configurations tailored to meet the needs of software
architects and XML developers. All MissionKits include the
world’s leading XML development tools: Altova
XMLSpy,
MapForce,
and StyleVision.
Gear
up; download a FREE 30-day trial today!
|
|