我想以一种方式合并两个数组,即第一个数组的值在子数组的第一个元素中转换,第二个数组的值在子数组的第二个元素中转换。这是我的例子:
Array01
(
[0] => 41558194
[1] => 44677841
[2] => 44503689
[3] => 40651770
)
Array02
(
[0] => 551
[1] => 546
[2] => 531
[3] => 519
)
mergedArray
(
[0] => Array([0] => 41558194 [1] => 551)
[1] => Array([0] => 44677841 [1] => 546)
[2] => Array([0] => 44503689 [1] => 531)
[3] => Array([0] => 40651770 [1] => 519)
)
最有效的方法是什么? 非常感谢提前!
答案 0 :(得分:1)
以下是使用array_map的简明示例:
function merge_arrays($a1, $a2) {
return array($a1, $a2);
}
$result = array_map("merge_arrays", $arr, $arr2);
答案 1 :(得分:0)
您的值的示例:
$array1 = array(
0 => 41558194,
1 => 44677841,
2 => 44503689,
3 => 40651770
);
$array2 = array(
0 => 551,
1 => 546,
2 => 531,
3 => 519
);
$finalArray = array();
foreach ($array1 as $key1 => $value1) {
$finalArray[$key1] = array($value1, $array2[$key1]);
}