Last active
July 30, 2020 19:55
-
-
Save arjenblokzijl/f8a2ba5bde3c26d82df0 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