Created
February 23, 2022 09:16
-
-
Save dankoch-cz/2fb7e512ea4c3cd1638a90822612b0da to your computer and use it in GitHub Desktop.
Read CSV file and return array with headers
This file contains hidden or 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 | |
| function read_csv($file_path,$delimiter) { | |
| $csv_rows = array(); | |
| $fp = fopen($file_path, 'r'); | |
| $head = fgetcsv($fp, 4096, $delimiter, '"'); | |
| // Rows | |
| while($column = fgetcsv($fp, 4096, $delimiter, '"')) | |
| { | |
| $csv_rows[] = array_combine($head, $column); | |
| } | |
| return $csv_rows; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment