Last active
October 17, 2017 16:12
-
-
Save devuri/887f609380e76117ca3f797f2f2aa4f8 to your computer and use it in GitHub Desktop.
Read CSV to ARRAY
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 get_csvarray($getcsvfile = 'test.csv'){ | |
| $row = 0; | |
| $col = 0; | |
| $gethandle = @fopen($getcsvfile, "r"); | |
| if ($gethandle) { | |
| while (($row = fgetcsv($gethandle, 4096)) !== false) { | |
| if (empty($fields)) { | |
| $fields = $row; | |
| continue; | |
| } | |
| foreach ($row as $k=>$value) { | |
| $outputarray[$col][$fields[$k]] = $value; | |
| } | |
| $col++; | |
| unset($row); | |
| } | |
| if (!feof($gethandle)) { | |
| echo "Error: unexpected fgets() failn"; | |
| } | |
| fclose($gethandle); | |
| } | |
| return $outputarray; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment