是否可以在文字键=>值对之前添加关联数组?我知道array_unshift()适用于数字键,但我希望能用于文字键的东西.
作为一个例子,我想做以下事情:
$array1 = array('fruit3'=>'apple', 'fruit4'=>'orange');
$array2 = array('fruit1'=>'cherry', 'fruit2'=>'blueberry');
// prepend magic
$resulting_array = ('fruit1'=>'cherry',
'fruit2'=>'blueberry',
'fruit3'=>'apple',
'fruit4'=>'orange');
Run Code Online (Sandbox Code Playgroud) 只是想用array_unshift在我的数组前面添加一个新参数,但是:如果我像往常一样,它有一个数字索引.如何拒绝索引,例如...
<?php
$queue = array("a", "B");
array_unshift($queue, "front" => "hello" ); //Not working, this is my question ;)
?>
Run Code Online (Sandbox Code Playgroud)
然后阵列看起来像
Array {
front => hello
0 => a
1 => B
}
Run Code Online (Sandbox Code Playgroud)