【发布时间】:2012-02-26 05:44:23
【问题描述】:
可能重复:
array_splice() for associative arrays
How to add an array value to the middle of an associative array?
如何在 PHP 中的关联数组中的特定关联键之后添加新的 [key] => [value] 对?
例如,假设我们有一个名为 $fruits 的数组:
array {
[apple] => 1
[banana] => 3
[orange] => 4
}
如何将[plum] => 2 添加到$fruits 以便它出现在[apple] 键之后但在[banana] 键之前?
谢谢。
【问题讨论】:
-
在这个例子中,看起来你想按值升序对数组进行排序,保持索引,又名
asort。 us.php.net/asort
标签: php arrays associative-array