Last active
August 29, 2015 14:12
-
-
Save iforwms/467e69a99f5e00a72b20 to your computer and use it in GitHub Desktop.
PHP: Get 2D Array From CSV
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
// PRODUCE A 2D ARRAY FROM CSV | |
function get2DArrayFromCsv($file, $delimiter) | |
{ | |
if (($handle = fopen($file, "r")) !== false) { | |
$i = 0; | |
while (($lineArray = fgetcsv($handle, 4000, $delimiter)) !== false) { | |
for ($j = 0; $j < count($lineArray); $j++) { | |
$data2DArray[$i][$j] = $lineArray[$j]; | |
} | |
$i++; | |
} | |
fclose($handle); | |
} | |
return $data2DArray; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment