如何在数组中插入单元,并带键值?

nationzhou 2010-08-13 12:09:58
<?php
$queue = array ("orange"=>1, "banana"=>3);
array_unshift ($queue, "apple", "raspberry");
?>
结果:
Array
(
[0] => apple
[1] => raspberry
[orange] => 1
[banana] => 3
)

我想要的结果:
Array
(
[apple] => 1
[raspberry] => 11
[orange] => 1
[banana] => 3
)
那array_unshift ($queue, "apple", "raspberry"); 应该怎么写?
...全文
363 点赞 收藏 4
写回复
4 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
phper_cd 2010-08-13
$queue = array ("orange"=>1, "banana"=>3);
$tmp = array("apple"=>11, "raspberry"=>1);

$result = array_merge($tmp, $queue);
print_r($result);

Array
(
[apple] => 11
[raspberry] => 1
[orange] => 1
[banana] => 3
)
回复
xuzuning 2010-08-13
$queue = array ("orange"=>1, "banana"=>3);
$tmp = array("apple"=>11, "raspberry"=>1);
print_r($tmp + $queue);


Array
(
[apple] => 11
[raspberry] => 1
[orange] => 1
[banana] => 3
)
回复
phper_cd 2010-08-13
直接赋值就可以了

$queue['apple'] =1;
$queue[raspberry] =11;
回复
zx119koko 2010-08-13
$queue['apple'] =1;
$queue[raspberry] =11;
回复
相关推荐
发帖
基础编程
创建于2007-09-28

2.1w+

社区成员

从PHP安装配置,PHP入门,PHP基础到PHP应用
申请成为版主
帖子事件
创建了帖子
2010-08-13 12:09
社区公告
暂无公告