Skip to content

Instantly share code, notes, and snippets.

@leonrenkema
Created April 7, 2015 12:09
Show Gist options
  • Save leonrenkema/17e7e060ad43daa44499 to your computer and use it in GitHub Desktop.
Save leonrenkema/17e7e060ad43daa44499 to your computer and use it in GitHub Desktop.
CSV to PHP array
<?php
function parseCSV($csvData) {
$result = [];
$rows = explode("\n", $csvData);
foreach ($rows as $key => $row) {
$cols = explode(";", $row);
$result[] = $cols;
}
return $result;
}
$data = parseCSV(file_get_contents('comp.csv'));
foreach ($data as $row) {
$rows[] = "array('" . implode("','", $row) . "')";
}
echo implode(",\n", $rows);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment