我有一个数组-我的数组的输出如下所示:
Array
(
["US"] => 186
["DE"] => 44
["BR"] => 15
["-"] => 7
["FR"] => 3
)
我想用"其他"代替"-"
所以最后应该是这样的:
Array
(
["US"] => 186
["DE"] => 44
["BR"] => 15
["other"] => 7
["FR"] => 3
)
有人能帮我吗?str_replace没有和我一起工作。。。如果可以的话,我想把数组的"另一部分"放在底部-像这样:
Array
(
["US"] => 186
["DE"] => 44
["BR"] => 15
["FR"] => 3
["other"] => 7
)
谢谢:)
当前代码:
$array_land = explode("'n", $land_exec_result);
$count_land = array_count_values($array_land);
arsort($count_land);
$arr['other'] = $count_land["-"];
unset($count_land["-"]);
但这对我来说并不奏效:/
很简单:
$array["other"] = $array["-"];
unset($array["-"]);
最后,阵列将是这样的:
Array
(
["US"] => 186
["DE"] => 44
["BR"] => 15
["FR"] => 3
["other"] => 7
)
$arr['other'] = $arr['-'];
unset($arr['-']);
第一个命令将$arr['-']
元素的值存储在名为$arr['other']
的新元素中。当您以这种方式为具有命名索引的数组创建新元素时,新元素将自动放置在数组的末尾。
第二个命令从数组中删除$arr['-']
元素。结果将是:
Array
(
["US"] => 186
["DE"] => 44
["BR"] => 15
["FR"] => 3
["other"] => 7
)