本文介绍了PHP prePEND关联数组字面钥匙?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有可能prePEND关联数组与文字键=>值对?我知道,array_unshift()适用于数字键,但我希望的东西,将与文字键的工作。
当我想要做如下的例子:
$ ARRAY1 =阵列('fruit3'=>'苹果','fruit4'=>'橙色');
$数组2 =阵列('fruit1'= GT;'樱桃','fruit2'=>'蓝莓');// prePEND魔术$ resulting_array =('fruit1'=>'樱桃',
fruit2'=>'蓝莓',
fruit3'=>苹果,
fruit4'=>'橙色');
解决方案
你就不能做的:
$ resulting_array = $数组2 + $数组1;
Is it possible to prepend an associative array with literal key=>value pairs? I know that array_unshift() works with numerical keys, but I'm hoping for something that will work with literal keys.
As an example I'd like to do the following:
$array1 = array('fruit3'=>'apple', 'fruit4'=>'orange');
$array2 = array('fruit1'=>'cherry', 'fruit2'=>'blueberry');
// prepend magic
$resulting_array = ('fruit1'=>'cherry',
'fruit2'=>'blueberry',
'fruit3'=>'apple',
'fruit4'=>'orange');
解决方案
Can't you just do:
$resulting_array = $array2 + $array1;
?
这篇关于PHP prePEND关联数组字面钥匙?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!