我将我的csv转换为关联数组,但是当我foreach
那个数组时,我没有得到第一个元素。我收到了undefined index
之类的警告
我的代码如下
if ($ext1 == "csv" && $_FILES["fileb"]["error"] == 0) {
$target1 = "upload/" . $_FILES["fileb"]["name"];
move_uploaded_file($_FILES["fileb"]["tmp_name"], $target1);
if (($handle1 = @fopen($target1, "r")) !== FALSE) {
$array1 = $fields1 = array();
$j = 0;
while (($row1 = fgetcsv($handle1, 4096)) !== false) {
if (empty($fields1)) {
$fields1 = $row1;
continue;
}
foreach ($row1 as $k => $value) {
$array1[$j][$fields1[$k]] = $value;
}
$j++;
}
fclose($handle1);
}
}
当foreach喜欢
foreach($array1 as $arr)
{
echo $arr['SCD']; // makes error like undefined index.
}
but second element and all getting
当print_r,我得到这样的
Array
(
[0] => Array
(
[SCD] => s000172
[SFN] => Alice
[SSN] => Powell
[SSC] => 09KG
[PCD1] => 124405
[PTI1] => Mrs
[PFN1] => Penny
[PSN1] => Powell
[PEM1] => gppowell@tpg.com.au
[CCD] => 09KG
[CLS] => 09KG
[CGN] => 09
[TCD] => HENE01
[TFN] => Erica
[TSN] => Hennigar
[TEM] => ehennigar@marymount.qld.edu.au
[TCD2] =>
[TFN2] =>
[TSN2] =>
[TEM2] =>
)
[1] => Array
(
[SCD] => s001272
[SFN] => Jay
[SSN] => Powell
[SSC] => 11AB
[PCD1] => 124405
[PTI1] => Mrs
[PFN1] => Penny
[PSN1] => Powell
[PEM1] => gppowell@tpg.com.au
[CCD] => 11AB
[CLS] => 11AB
[CGN] => 11
[TCD] => HORE02
[TFN] => Ebony
[TSN] => Horn
[TEM] => Ebony.Horn@marymount.qld.edu.au
[TCD2] =>
[TFN2] =>
[TSN2] =>
[TEM2] =>
)