如何将项添加到关联数组的开头?例如,假设我有一个这样的数组:PHP - 将项目添加到关联数组的开头
$arr = array('key1' => 'value1', 'key2' => 'value2');
当我添加的东西给它在$arr['key0'] = 'value0';
,我得到:
Array ( [key1] => value1 [key2] => value2 [key0] => value0 )
怎样使这是
Array ( [key0] => value0 [key1] => value1 [key2] => value2 )
谢谢,
Tee
请注意,[最小代码示例](https://sscce.org/)比单独使用变量转储更有帮助(尽管后者也可能有所帮助)。 – outis 2011-04-25 22:04:53
[PHP prepend关联数组与文字键?]可能的重复?(http://stackoverflow.com/questions/1371016/php-prepend-associative-array-with-literal-keys)。另请参阅:[PHP:Array_unshift非数字索引](http://stackoverflow.com/questions/4516664/php-array-unshift-an-not-numeric-index)。 – outis 2011-04-25 22:11:54