Created
July 23, 2013 12:33
-
-
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
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
<?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