我正在上傳一個csv文件,然後使用str_getcsv解析它。所有的作品都很棒,除了我需要一種方法來循環它們。理想情況下,這將會是巨大的,有陣回來,看起來像這樣:php 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);
[PHP的CSV字符串數組]可能的重複(http://stackoverflow.com/questions/17761172/php-csv-string-to-array) – user
我已經標記爲重複,儘管事實上這問題是早些時候,因爲這個問題更受歡迎 – user