我正在编写一个导入 csv 并插入到表中的 PHP 脚本,但我需要获取第一行,以便我可以拥有字段名称..这是我的 csv
id artist song
11 NewBee great stuff
10 anotherNewbee even better
6 NewArtist New song
如您所见,第一行是我需要的字段的名称。这是我的循环
$handle = fopen('csvs/'.$_FILES["csv"]["name"], 'r');
while (($data = fgetcsv($handle, 1000, ',')) !== FALSE) {
print_r($data);
//do something with it but i need the first time around
array(3) { [0]=> string(2) "id" [1]=> string(6) "artist" [2]=> string(4) "song" }
array(3) { [0]=> string(2) "11" [1]=> string(6) "NewBee" [2]=> string(1) "great stuff" }
array(3) { [0]=> string(2) "10" [1]=> string(13) "anotherNewbee" [2]=> string(1) "even better"}
我如何获得第一个并将它们放入变量中并使用插入语句中的这些字段继续数据循环