我正在写一个导入CSV并插入到表中的PHP脚本,但我需要得到的第一行,这样我可以有场names..here是我的CSVwhile循环中的第一个元素?
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"}
我如何获得第一,并把它们放在变量和继续使用这些字段在INSERT语句
使用Markdown来设置您的帖子的格式,以便您的代码更具可读性(我已为您完成)。 [本页显示如何。](http://stackoverflow.com/editing-help) – BoltClock 2010-11-02 02:44:14
@BoltClock - 再次感谢! – zerodin 2010-11-02 02:50:30
非常感谢这篇文章! – user3943543 2017-04-11 19:51:34