Skip to content

Instantly share code, notes, and snippets.



Last active Aug 29, 2015
What would you like to do?
Read CSV Into 2 Dimensional Array
// Auto detect line endings so more CSV's are compatible.
ini_set("auto_detect_line_endings", true);
// Read a CSV and make a 2 dimensional array from the data
// Pass the name of the CSV as an argument when calling the funciton.
function readCSV($filename) {
$data = array();
if (file_exists($filename)) {
$file = fopen($filename, 'r'); // r = read, w = write, a = append
while (($result = fgetcsv($file, 1000, ",")) !== false) {
$data[] = $result;
return $data;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment