How to make the header row be skipped in my while loop using fgetcsv?

后端 未结 2 548
春和景丽
春和景丽 2021-01-13 14:04

I can\'t get the new code I\'ve written to skip the first row (header) as the code I was using before did (see bottom).

I\'m not receiving any errors, but just can\

相关标签:
2条回答
  • 2021-01-13 14:17

    Why even count? Just get the headers before looping.

    $column_headers = fgetcsv($file);
    while(!feof($file)) {
       ...
    

    Also, you're only assigning the file pointer to the variable.

    0 讨论(0)
  • 2021-01-13 14:21

    When $row_count is 0 you are not reading any row.

    Change

    if ($row_count==0){
        $column_headers = $file;  // just assigning file handle.
    }
    

    to

    if ($row_count==0){
        $column_headers = fgetcsv($file); // read the row.
    }
    
    0 讨论(0)
提交回复
热议问题