我有一個CSV文件和前兩列頭閱讀CSV文件到數組並跳過第一行PHP
'Student','ID','SIS User ID'
Points Possible
Ashe, 797389, 11721809
Darius, 20237, 55050811
Fizz, 34604, 55035088
Tom Kenn,20232, 55050802
Vayne, 797413, 11813445
對於前兩列,他們不應該被添加到陣列中。 從阿什開始,我想Ashe, 797389, 11721809
行添加到array[0]
大流士array[1]
,....
我寫我的代碼如下:
<?php
$csvData = file_get_contents('output.csv');
$lines = explode(PHP_EOL, $csvData);
$array = array();
foreach ($lines as $line) {
$array[] = str_getcsv($line);
}
print_r($array[2][5]);
?>
我應該以跳過做前兩行?
修復問題後,出現一個空數組。如何消除空陣列?
[797413] => Array
(
[0] => Vayne
[1] => 797413
[2] => 11813445
[3] => lsmdec
[4] => cs3487
[5] => 12.15
[6] => 15
[7] => 5
[8] => 17
[9] => 49.15
[10] => 49.15
[11] => 49.15
[12] => 49.15
[13] => 49.15
[14] => 49.15
[15] => 49.15
[16] => 49.15
[17] => C-
[18] => C-
)
[] => Array
(
[0] =>
)
它的作品! Thx爲您提供幫助!它拯救了我的一天! – killer2318
@ killer2318不客氣! – FMashiro
[797413] =>數組 ( [0] => Vayne [1] => 797413 [2] => 11813445 [3] => lsmdec [4] => cs3487 [5] => 12.15 [6] => 15 [7] => 5 [8] => 17 [9] => 49.15 [10] => 49.15 [11] => 49.15 [12] => 49.15 [13] => 49.15 [14] => 49.15 [15] => 49.15 [16] => 49.15 [17] => C- [18] => C-(0)=> ) – killer2318