我有两个独立的阵列。现在我想使用现有的两个数组创建多维数组。 这是我的两个独立数组 -
Array
(
[0] => 11
[1] => 22
[2] => 33
[3] => 44
)
-------------------
Array
(
[0] => 555
[1] => 666
[2] => 777
[3] => 888
)
我想要多维数组的结果,即 -
Array
(
[0] => Array
(
[0] => 11
[demoid] => 11
[1] => 555
[demovalue] => 555
)
[1] => Array
(
[0] => 22
[demoid] => 22
[1] => 666
[demovalue] => 666
)
[2] => Array
(
[0] => 33
[demoid] => 33
[1] => 777
[demovalue] => 777
)
)
答案 0 :(得分:2)
只需循环并将值添加到新数组中 - 我不明白为什么你会这么努力......
$new_array = array();
foreach($array1 as $key => $val) {
$new_array[] = array( 0 => $val,
'demoid' => $val,
1 => $array2[$key],
'demovalue' => $array2[$key]);
}