Skip to content

Instantly share code, notes, and snippets.

@marianmirzacu
Last active November 13, 2017 08:26
Show Gist options
  • Save marianmirzacu/d721e10654b2afefc833e65cc5dfd8de to your computer and use it in GitHub Desktop.
Save marianmirzacu/d721e10654b2afefc833e65cc5dfd8de to your computer and use it in GitHub Desktop.
PHP transform CSV to Array - does NOT support line breaks in CSV fields
public function csvToArray ($csv_file) {
$csv = array_map(function($csv_file) {
return str_getcsv($csv_file, ";");
}, file($csv_file, FILE_SKIP_EMPTY_LINES));
$keys = array_shift($csv);
foreach ($csv as $i=>$row) {
$csv[$i] = array_combine($keys, $row);
}
return $csv;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment