我需要将 2 个多维数组合并在一起以创建一个新数组.
这 2 个数组是从 $_POST 和 $_FILES 创建的,我需要它们相互关联.
I need to merge 2 multidimensional arrays together to create a new array.
The 2 arrays are created from $_POST and $_FILES and I need them to be associated with each other.
数组#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 函数,它会在每个循环中擦除我的新数组.
The current code i'm using works, but only for the last item in the array.
I'm presuming by looping the array_merge function it wipes my new array every loop.
$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++;
}
[] 会将它附加到数组中而不是覆盖.
the [] will append it to the array instead of overwriting.
这篇关于PHP:合并 2 个多维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
在 SELECT(MYSQL/PHP) 中加入 2 个表Joining 2 tables in SELECT(MYSQL/PHP)(在 SELECT(MYSQL/PHP) 中加入 2 个表)
如何使<option selected=“selected">由How to make lt;option selected=quot;selectedquot;gt; set by MySQL and PHP?(如何使lt;option selected=“selectedgt;由 MySQL 和 PHP 设置?)
使用 PHP 中的数组自动填充选择框Auto populate a select box using an array in PHP(使用 PHP 中的数组自动填充选择框)
PHP SQL SELECT where like search item with multiple wordsPHP SQL SELECT where like search item with multiple words(PHP SQL SELECT where like search item with multiple words)
json_encode 从 MSSQL-SELECT 产生 JSON_ERROR_UTF8json_encode produce JSON_ERROR_UTF8 from MSSQL-SELECT(json_encode 从 MSSQL-SELECT 产生 JSON_ERROR_UTF8)
MySQL ORDER BY rand(),名称 ASCMySQL ORDER BY rand(), name ASC(MySQL ORDER BY rand(),名称 ASC)