Skip to content

Instantly share code, notes, and snippets.

@manticorp
Last active December 14, 2015 20:19
Show Gist options
  • Save manticorp/5142979 to your computer and use it in GitHub Desktop.
Save manticorp/5142979 to your computer and use it in GitHub Desktop.
A simple function to convert a CSV file to an array:
function csv_to_array($filename='', $delimiter=',',$header = NULL)
{
if(!file_exists($filename) || !is_readable($filename))
return FALSE;
$data = array();
if (($handle = fopen($filename, 'r')) !== FALSE)
{
while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE)
{
if(!$header)
$header = $row;
else
$data[] = 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