Skip to content

Instantly share code, notes, and snippets.

@DanielVeza
Last active June 21, 2021 01:16
Show Gist options
  • Save DanielVeza/af17b09e6ba1a11c698a3580f089875b to your computer and use it in GitHub Desktop.
Save DanielVeza/af17b09e6ba1a11c698a3580f089875b to your computer and use it in GitHub Desktop.
<?php
function csvToArray($string $path, boolean $removeHeader = true) : array {
$realPath = drupal_realpath($path);
// CSV to array
$csvRows = array_map('str_getcsv', file($realPath));
if ($removeHeader) {
// Remove header row
unset($csvRows[0]);
}
return $csvRows;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment