【发布时间】:2016-05-09 18:38:39
【问题描述】:
我正在尝试添加两个数组 $arraydata1 和 $arraydata2 以获取数组 $result。但它显示的结果好像$result=$arraydata1;,而不是
$result=$arraydata1+$arraydata2;.
这是我从 CSV 文件中获取它并将其存储在不同的数组类型变量中后尝试添加的数组。
$result = array();
$arraydata1 = array();
$arraydata2 = array();
$key1 = array("itemid","itembrand","itemname","itemmodel","itemdesc","itemtype","itemprice","itemimgfolder","itemimage");
$key2 = array("itemid","itembrand","itemname","itemmodel","itemdesc","itemtype","itemprice","itemimgfolder","itemimage");
foreach (file('data/dell/data.csv') as $key => $str)
{
if ($key == 0) continue; // to skip headings of the csv file
$values = str_getcsv($str, "\t", '', '');
$arraydata1[] = array_combine($key1, $values);
} // to store first array data
foreach (file('data/hp/data.csv') as $key => $str)
{
if ($key == 0) continue; // to skip headings of the csv file
$values = str_getcsv($str, "\t", '', '');
$arraydata2[] = array_combine($key2, $values);
}
$result = $arraydata2+$arraydata2; // result the combination of the two arrays
其他一切正常。我也试过array_combine(),但也没用。
【问题讨论】:
-
是的
$result = array_merge($arraydata2,$arraydata1);是替代解决方案。