我需要将2个多维数组合并在一起以创建一个新数组。 这两个数组是从$_POST和创建的$_FILES,我需要将它们彼此关联。
$_POST
$_FILES
数组#1
Array ( [0] => Array ( [0] => 123 [1] => "Title #1" [2] => "Name #1" ) [1] => Array ( [0] => 124 [1] => "Title #2" [2] => "Name #2" ) )
阵列#2
Array ( [name] => Array ( [0] => Image001.jpg [1] => Image002.jpg ) )
新阵列
Array ( [0] => Array ( [0] => 123 [1] => "Title #1" [2] => "Name #1" [3] => "Image001.jpg" ) [1] => Array ( [0] => 124 [1] => "Title #2" [2] => "Name #2" [3] => "Image002.jpg" ) )
我正在使用的当前代码有效,但仅适用于数组中的最后一项。 我想通过循环该array_merge函数在每个循环中擦除新数组。
array_merge
$i=0; $NewArray = array(); foreach($OriginalArray as $value) { $NewArray = array_merge($value,array($_FILES['Upload']['name'][$i])); $i++; }
我该如何纠正?
$i=0; $NewArray = array(); foreach($OriginalArray as $value) { $NewArray[] = array_merge($value,array($_FILES['Upload']['name'][$i])); $i++; }
[]会将其附加到数组而不是覆盖。