Skip to content

Instantly share code, notes, and snippets.

@dankoch-cz
Created February 23, 2022 09:16
Show Gist options
  • Select an option

  • Save dankoch-cz/2fb7e512ea4c3cd1638a90822612b0da to your computer and use it in GitHub Desktop.

Select an option

Save dankoch-cz/2fb7e512ea4c3cd1638a90822612b0da to your computer and use it in GitHub Desktop.
Read CSV file and return array with headers
<?php
function read_csv($file_path,$delimiter) {
$csv_rows = array();
$fp = fopen($file_path, 'r');
$head = fgetcsv($fp, 4096, $delimiter, '"');
// Rows
while($column = fgetcsv($fp, 4096, $delimiter, '"'))
{
$csv_rows[] = array_combine($head, $column);
}
return $csv_rows;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment