Created
July 5, 2021 16:53
-
-
Save angelorocha/85234d7bf769811c9278ed513e98fe32 to your computer and use it in GitHub Desktop.
Convert CSV file in 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 | |
/** | |
* Convert CSV file in Array | |
* | |
* @param string $file_csv CSV file path | |
* | |
* @return array|string | |
*/ | |
function csv_to_array(string $file_csv){ | |
if(!file_exists($file_csv)): | |
return 'File not found...'; | |
endif; | |
if(pathinfo($file_csv)['extension'] !== 'csv' && mime_content_type($file_csv) !== 'text/plain'): | |
return 'File type not allowed, send a CSV file...'; | |
endif; | |
return array_map('str_getcsv', file($file_csv)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment