PHP array_shift() 函数

PHP 教程 · 2019-01-22 13:44:31

实例

删除数组中的第一个元素(red),并返回被删除的元素:

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

定义和用法

array_shift() 函数用于删除数组中的第一个元素,并返回被删除的元素。

注释:如果键名是数字的,所有元素都将获得新的键名,从 0 开始,并以 1 递增(参见下面实例)。

语法

array_shift(array)

参数 描述
array 必需。规定数组。

技术细节

返回值: 返回从数组中删除元素的值,如果数组为空则返回 NULL。
PHP 版本: 4+

更多实例

实例 1

使用数字键名:

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

点击查看所有 PHP 教程 文章: https://www.codercto.com/courses/l/5.html

查看所有标签

HTTP

HTTP

David Gourley、Brian Totty、Marjorie Sayer、Anshu Aggarwal、Sailu Reddy / O'Reilly Media / 2002-10-7 / USD 54.99

Product Description Web technology has become the foundation for all sorts of critical networked applications and far-reaching methods of data exchange, and beneath it all is a fundamental protocol......一起来看看 《HTTP》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

html转js在线工具
html转js在线工具

html转js在线工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具