我如何对关联数组进行 array_merge,如下所示:
Array 1:
$options = array (
"1567" => "test",
"1853" => "test1",
);
Array 2:
$option = array (
"none" => "N/A"
);
所以我需要 array_merge 这两个,但是当我这样做时我得到这个(在调试中):
Array
(
[none] => N/A
[0] => test
[1] => test1
)
尝试使用:
$finalArray = $选项 + $选项 .see http://codepad.org/BJ0HVtac只需检查重复键的行为,我没有对此进行测试。对于唯一的键,它效果很好。
<?php
$options = array (
"1567" => "test",
"1853" => "test1",
);
$option = array (
"none" => "N/A"
);
$final = array_merge($option,$options);
var_dump($final);
$finalNew = $option + $options ;
var_dump($finalNew);
?>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)