Forked from arjenblokzijl/convert-csv-file-to-php-associative-array.php
Created
December 17, 2017 06:36
-
-
Save davemac/bb84ebca5a07bc378c9bbb0758d25b6e to your computer and use it in GitHub Desktop.
Convert CSV file to PHP associative array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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