Skip to content

Instantly share code, notes, and snippets.

@davidverhage
Created September 3, 2020 09:34
Show Gist options
  • Save davidverhage/29a90a0a23ad83e365cf5ee3bffbd5dc to your computer and use it in GitHub Desktop.
Save davidverhage/29a90a0a23ad83e365cf5ee3bffbd5dc to your computer and use it in GitHub Desktop.
Associative array from CSV
<?php
/* Thanks to http://steindom.com/articles/shortest-php-code-convert-csv-associative-array */
ini_set('auto_detect_line_endings', TRUE);
$rows = array_map('str_getcsv', file('myfile.csv'));
$header = array_shift($rows);
$csv = array();
foreach ($rows as $row) {
$csv[] = array_combine($header, $row);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment