Voting

: max(zero, zero)?
(Example: nine)

The Note You're Voting On

Jay Williams
14 years ago
Here is a quick and easy way to convert a CSV file to an associated array:

<?php
/**
* @link http://gist.github.com/385876
*/
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
$data[] = array_combine($header, $row);
}
fclose($handle);
}
return
$data;
}

?>

<< Back to user notes page

To Top