Created
December 1, 2012 16:17
-
-
Save drakakisgeo/4183073 to your computer and use it in GitHub Desktop.
Csv File to multidimentional Array
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
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