Skip to content

Instantly share code, notes, and snippets.

@AlexPashley
Created July 23, 2013 12:33
Show Gist options
  • Save AlexPashley/6062027 to your computer and use it in GitHub Desktop.
Save AlexPashley/6062027 to your computer and use it in GitHub Desktop.
PHP: Load a CSV file and convert it to a multi dimensional array
<?php
/**
* Converts CSV to multi dimensional array
*/
function csv_to_multidimension_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 ) {
$data[] = $row;
}
fclose($handle);
}
return $data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment