Skip to content

Instantly share code, notes, and snippets.

@tschifftner
Created February 22, 2022 09:53
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 tschifftner/1790dce593e20ca057bb5226d2007b22 to your computer and use it in GitHub Desktop.
Save tschifftner/1790dce593e20ca057bb5226d2007b22 to your computer and use it in GitHub Desktop.
Helper function to load csv file into array
<?php
public function loadCsvFileToArray($filepath)
{
$resource = fopen($filepath, 'r');
$columns = fgetcsv($resource, null, ',', '"');
$collection = [];
while($data = fgetcsv($resource, null, ',', '"')) {
$row = array_combine($columns, $data);
$collection[] = $row;
}
fclose($resource);
return $collection;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment