One liner to get a CSV file into 2-dimentional array NB! Only works if “,” is the separator!!! NB! Does not work if CSV cells have line breaks in them!!!
$csv = array_map('str_getcsv', file('data.csv'));
Work with each line in a CSV file:
$handle = fopen("data_sample_5_sec.csv", "r"); $is_first_row_header = true; for ($i = 0; $row = fgetcsv($handle, null, ";"); ++$i) { if ($is_first_row_header AND $i == 0) { $headers = $row; continue; } // Do something with $row array $row['']; } fclose($handle);