Created
February 22, 2022 09:53
-
-
Save tschifftner/1790dce593e20ca057bb5226d2007b22 to your computer and use it in GitHub Desktop.
Helper function to load csv file into array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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