Last active
December 18, 2015 22:39
-
-
Save michaelcurry/5855818 to your computer and use it in GitHub Desktop.
Simple CSV to array function. if Header == NULL then the first row will be the header.
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
/** | |
* @link https://gist.github.com/michaelcurry/5855818 | |
*/ | |
function csv_to_array($filename, $delimiter = ',', $header = NULL){ | |
$array = array(); | |
$rows = file($filename); | |
foreach($rows as $line) { | |
$tmp = str_getcsv($line, $delimiter); | |
if( ! $header ) { | |
$header = $tmp; | |
} else { | |
$array[] = array_combine($header, $tmp); | |
} | |
} | |
return $array; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment