Skip to content

Instantly share code, notes, and snippets.

@adeel-raza
Created May 5, 2017 09:57
Show Gist options
  • Save adeel-raza/589797fbcf4cfd7fa7289540b7918f40 to your computer and use it in GitHub Desktop.
Save adeel-raza/589797fbcf4cfd7fa7289540b7918f40 to your computer and use it in GitHub Desktop.
Parse a CSV as an associate array with column names as keys and row as values
$csv = array_map("str_getcsv", file("file1.csv",FILE_SKIP_EMPTY_LINES));
$keys = array_shift($csv);
foreach ($csv as $i=>$row) {
$csv[$i] = array_combine($keys, $row);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment