Created
October 18, 2016 16:31
-
-
Save dgtal/3e188d8ff76e8abfdab9b23bbc167ece to your computer and use it in GitHub Desktop.
This file contains hidden or 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 csv_to_array($filename='', $delimiter=',') | |
{ | |
if (!file_exists($filename) || !is_readable($filename)) | |
return FALSE; | |
$header = NULL; | |
$data = array(); | |
if (($handle = fopen($filename, 'r')) !== FALSE) { | |
while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE) { | |
if (!$header) | |
$header = $row; | |
else { | |
// Primer columna como key | |
$data[$row[1]] = array_combine($header, $row); | |
} | |
} | |
fclose($handle); | |
} | |
return $data; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment