我有这两个数组
Array
(
[0] => Array
(
[text] => 1ofdays.wav
)
[1] => Array
(
[text] => abcd.mp3
)
)
Array
(
[0] => Array
(
[value] => 6
)
[1] => Array
(
[value] => 7
)
)
无论如何,我可以将这两个数组合并到新的数组数组中,结果应该是
NewArray
(
[0] => Array
(
[text] => 1ofdays.wav,
[value]=>6
)
[1] => Array
(
[text] => abcd.mp3,,
[value]=>7
)
)
当我将json编码新数组时,输出应为
[{"text":"1ofdays.wav","value":"6"},{"text":"abcd.mp3","value","7"}]
答案 0 :(得分:0)
您可以使用array_merge
答案 1 :(得分:0)
您可以使用array_map
并以array_merge_recursive
作为回调来执行此操作:
$arr1 = [['text' => '1ofdays.wav'], ['text' => 'abcd.mp3']];
$arr2 = [['value' => 6], ['value' => 7]];
$result = array_map('array_merge_recursive', $arr1, $arr2);
var_dump($result);
输出:
array (size=2)
0 =>
array (size=2)
'text' => string '1ofdays.wav' (length=11)
'value' => int 6
1 =>
array (size=2)
'text' => string 'abcd.mp3' (length=8)
'value' => int 7