Skip to content

Instantly share code, notes, and snippets.

@michaelcurry
Last active December 18, 2015 22:39
Show Gist options
  • Save michaelcurry/5855818 to your computer and use it in GitHub Desktop.
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.
/**
* @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