插入元素 "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+ | 
更多实例
Show the return value:
实例 1
Run this code »<?php
    $a = array("a" => "red", "b" => "green");
    print_r(array_unshift($a, "blue"));
    ?>Using numeric keys:
实例 2
Run this code »<?php
    $a = array(0 => "red", 1 => "green");
    array_unshift($a, "blue");
    print_r($a);
    ?> 自学教程
自学教程
分享笔记