Skip to content

Instantly share code, notes, and snippets.

@marco-kretz
Created April 20, 2018 14:51
Show Gist options
  • Save marco-kretz/1ab44bf1f7677e53ab25f96d70c04803 to your computer and use it in GitHub Desktop.
Save marco-kretz/1ab44bf1f7677e53ab25f96d70c04803 to your computer and use it in GitHub Desktop.
public function readCSVWithHeaders($csvString, $delimiter = ';')
{
$rows = explode("\n", str_replace("\r", '', $csvString));
$headers = str_getcsv(array_shift($rows), $delimiter);
return array_map(function ($row) use ($headers, $delimiter) {
return array_combine($headers, str_getcsv($row, $delimiter));
}, array_filter($rows, function($row) {
return !empty($row);
}));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment