Question

In PHP, how to read or parse a .cvs file with the first row as column name?


Annonce
Ad

Answer

// Read the file to the array $csv
$csv = array_map("str_getcsv", file('filename.csv',FILE_SKIP_EMPTY_LINES));
// Extract keys (column names) from first line of $csv
$keys = array_shift($csv);
// Combine the arrays $csv and $keys for each row
foreach ($csv as $i=>$row) $data[$i] = array_combine($keys, $row);


[source]
# ID Query