PHP:Array_unshift的不是数字索引 [英] PHP: Array_unshift an not numeric index
本文介绍了PHP:Array_unshift的不是数字索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
只是想在我的阵列array_unshift前面添加一个新的参数,但如果我不喜欢它往常一样,它有一个数字索引。我怎么能拒绝指标,例如类似的东西...
< PHP
$队列=阵列(一,B);
array_unshift($队列,前=>你好); //不工作,这是我的问题;)
?>
该数组然后像
阵列{
前面=>你好
0 =>一个
1 =>乙
}
解决方案
看起来像array_unshift不能做你想做的。试试这个:
$队列=阵列('A','B');
$队列= array_merge(阵列('前'=>'你好'),$队列);
这给你想要的结果。
排列
(
[前端] =>你好
[0] =>一
[1] =>乙
)
Just wanted to add a new parameter in the front of my array with array_unshift, but: If I do it like usual, it has an numeric index. How can I decline the index, e.g. something like that...
<?php
$queue = array("a", "B");
array_unshift($queue, "front" => "hello" ); //Not working, this is my question ;)
?>
The array would then look like
Array {
front => hello
0 => a
1 => B
}
解决方案
Looks like array_unshift cannot do what you want. Try this:
$queue = array('a', 'B');
$queue = array_merge(array('front' => 'hello'), $queue);
This gives the result you want.
Array ( [front] => hello [0] => a [1] => b )
这篇关于PHP:Array_unshift的不是数字索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文