Skip to content

Instantly share code, notes, and snippets.

@iforwms
Last active August 29, 2015 14:12
Show Gist options
  • Save iforwms/467e69a99f5e00a72b20 to your computer and use it in GitHub Desktop.
Save iforwms/467e69a99f5e00a72b20 to your computer and use it in GitHub Desktop.
PHP: Get 2D Array From CSV
// 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