Skip to content

Instantly share code, notes, and snippets.

@rcknr
Created October 2, 2015 22:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rcknr/71b1ae32a40dfa29bdca to your computer and use it in GitHub Desktop.
Save rcknr/71b1ae32a40dfa29bdca to your computer and use it in GitHub Desktop.
Convert a CSV file to an associative array
<?php
$source = file('http://example.com/example.csv');
$csv_array = array_map('str_getcsv', $source, array_fill(0, count($source), ';'));
$header = array_shift($csv_array);
$result = array_map('array_combine', array_fill(0, count($csv_array), $header), $csv_array);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment