Skip to content

Instantly share code, notes, and snippets.

@drakakisgeo
Created December 1, 2012 16:17
Show Gist options
  • Save drakakisgeo/4183073 to your computer and use it in GitHub Desktop.
Save drakakisgeo/4183073 to your computer and use it in GitHub Desktop.
Csv File to multidimentional Array
function csv2array($file,$head=true,$delim=",",$len=1000) {
$return = false;
$handle = fopen($file, "r");
if ($head) {
$header = fgetcsv($handle, $len, $delim);
}
while (($data = fgetcsv($handle, $len, $delim)) !== FALSE) {
if ($head AND isset($header)) {
foreach ($header as $key=>$heading) {
$row[$heading]=(isset($data[$key])) ? $data[$key] : '';
}
$return[]=$row;
} else {
$return[]=$data;
}
}
fclose($handle);
return $return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment