PHP array_unshift() 函数

PHP 教程 · 2019-01-22 16:27:56

实例

插入元素 "blue" 到数组中:

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

定义和用法

array_unshift() 函数用于向数组插入新元素。新数组的值将被插入到数组的开头。

提示:您可以插入一个或多个值。

注释:数值键名将从 0 开始,以 1 递增。字符串键名将保持不变。

语法

array_unshift(array,value1,value2,value3...)

参数 描述
array 必需。规定数组。
value1 必需。规定插入的值。
value2 可选。规定插入的值。
value3 可选。规定插入的值。

技术细节

返回值: 返回新数组中元素的个数。
PHP 版本: 4+

更多实例

实例 1

Show the return value:

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

实例 2

Using numeric keys:

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

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

查看所有标签

Beginning iPhone and iPad Web Apps

Beginning iPhone and iPad Web Apps

Chris Apers、Daniel Paterson / Apress / 2010-12-15 / USD 39.99

It seems that everyone and her sister has developed an iPhone App—everyone except you, the hard-working web professional. And now with the introduction of the iPad, you may even feel farther behind. B......一起来看看 《Beginning iPhone and iPad Web Apps》 这本书的介绍吧!

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器

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

html转js在线工具

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试