PHP 数组函数

array_shift()函数是 PHP 的内置函数。 array_shift( ) 函数用于从数组中删除第一个元素,并返回删除元素的值。此函数是在 PHP 4.0 中引入的。

语法

mixed array_shift ( array &$array ); 

参数

参数描述必须/可选
array指定数组必须

返回值

array_shift( ) 函数返回从数组中删除的元素的值。如果数组为空,它将返回 NULL。

重要提示:如果键是数字,所有元素都会得到新的键,从0开始,递增1。

例子1

<?php
$match=array(0=>"test",1=>"one day",2=>"t20");
echo array_shift($match);
print_r ($match);
?> 

输出:

testArray
(
[0] => one day
[1] => t20
)

例子2

<?php
$subject = array(0 => 'science', 1=> 'math', 2 => 'english',3 => 'chinese');
$result= array_shift($subject);
print_r($subject);
print_r($result);
?> 

输出:

Array
(
[0] => math
[1] =>english
[2] =>chinese
)
Science