我有两个数组,我只是想在一个函数中合并在一起:
$var1=array();
$myInputVar=array();
$var1['something']['secondary_something'][]="foo1";
$var1['something']['secondary_something'][]="foo2";
$var1['something']['secondary_something'][]="foo3";
$myInputVar['something']['secondary_something'][]="foo4";
$myInputVar['something']['secondary_something'][]="foo5";
function something(&$array_, $array_new) {
$array = array_merge($array_ , $array_new);
print_r($array);//for debugging
}
something($var1, $myInputVar);
现在打印:
Array ( [something] => Array ( [secondary_something] => Array ( [0] => foo1 [1] => foo2 [2] => foo3 ) ) )
当我期待:
Array ( [something] => Array ( [secondary_something] => Array ( [0] => foo1 [1] => foo2 [2] => foo3 [3] => foo4 [4] => foo5) ) )
我也试过:
$array = $array_ + $array_new;
仍然没有打印出我的期望。
我有一种感觉,我误解了array_merge()
函数的目的,这就是为什么它没有返回我期望它返回的结果。
有任何想法吗?