超越PHP PHP动态 | 经典文章 | CLASS | 相关下载 | 常见问题 | FORUM | WIKI | 在线手册
Site search:    
<array_uniquearray_values>
Last updated: Fri, 22 Jun 2007

array_unshift

(PHP 4 , PHP 5)

array_unshift --  在数组开头插入一个或多个单元

说明

int array_unshift ( array array, mixed var [, mixed ...])

array_unshift() 将传入的单元插入到 array 数组的开头。注意单元是作为整体被插入的,因此传入单元将保持同样的顺序。所有的数值键名将修改为从零开始重新计数,所有的文字键名保持不变。

返回 array 数组新的单元数目。

例子 1. array_unshift() 例子

<?php
$queue
= array ("orange", "banana");
array_unshift ($queue, "apple", "raspberry");
?>

这将使 $queue 包含如下单元:

Array
(
   [0] => apple
   [1] => raspberry
   [2] => orange
   [3] => banana
)

参见 array_shift()array_push()array_pop()




add a note add a note User Contributed Notes
array_unshift
matt at synergie dot net
19-Sep-2000 01:20
The behaviour of unshift nearly caught me out.
Not only is the item added at the start of the list but the list is re-indexed too.

<?php

$a = array(5=>"five", 6 =>"six", 20 => "twenty");

while(list($key, $value) = each($a))
echo "k: $key v: $value
\n";

echo "
\n";
array_unshift($a, "zero");


while(list($key, $value) = each($a))
echo "k: $key v: $value
\n";

?>

k: 5 v: five
k: 6 v: six
k: 20 v: twenty

k: 0 v: zero
k: 1 v: five
k: 2 v: six
k: 3 v: twenty

<array_uniquearray_values>
 Last updated: Fri, 22 Jun 2007
view source | feedback | send page | sitemap | aboutus   
Copyright ® 2002-2003 PHPE.NET. All rights reserved
Last updated:2002-11-22