Last active
November 13, 2017 08:26
-
-
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
This file contains 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
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