user1148297
user1148297

Reputation: 23

Read header of CSV separately

I am reading a large CSV file through fgetcsv(). I want to read the header of the file and the data separately. Below is my code. Any help?

$msg_row = 1;
while (($result = fgetcsv($msg_file,1000, ",")) !== false)
{   
    $msg_data[] = $result;
    $msg_row++;
}

Upvotes: 1

Views: 82

Answers (1)

Ry-
Ry-

Reputation: 224942

So call it once first?

$msg_row = 1;
$header = fgetcsv($msg_file, 1000, ",");
while (($result = fgetcsv($msg_file, 1000, ",")) !== false)
{   
    $msg_data[] = $result;
    $msg_row++;
}

Upvotes: 4

Related Questions