我正在上传一个CSV文件,并使用str_getcsv解析它。所有操作都很好,除了我需要一种遍历的方法。理想情况下,希望数组返回并长成这样:
然而,数据返回的格式如下:
有没有关于如何修复这个问题,使其看起来像上面的数组的建议? 现在我正在做:
Array (
[1] => Array
(
[0] => 1 // first id in csv
[1] => name
[2] => address
[3] => town
[4] => state
[5] => zip
[6] => phone
[7] => website
[8] => other
[9] => other
)
[22] => Array
(
[10] => name
[11] => address
[12] => town
[13] => state
[14] => zip
[15] => phone
[16] => website
[17] => other
[18] => other
)
[24] => Array
(
[19] => name
[20] => address
[21] => town
[22] => state
[23] => zip
[24] => phone
[25] => website
[26] => other
[27] => other
)
)
然而,数据返回的格式如下:
Array
(
[0] => 1 // first id in csv
[1] => name
[2] => address
[3] => town
[4] => state
[5] => zip
[6] => phone
[7] => website
[8] => other
[9] => other
22 // id field
[10] => name
[11] => address
[12] => town
[13] => state
[14] => zip
[15] => phone
[16] => website
[17] => other
[18] => other
24// id field
[19] => name
[20] => address
[21] => town
[22] => state
[23] => zip
[24] => phone
[25] => website
[26] => other
[27] => other
有没有关于如何修复这个问题,使其看起来像上面的数组的建议? 现在我正在做:
$csvfile = file_get_contents($targetFile);
$csv = str_getcsv($csvfile);