Skip to content

Instantly share code, notes, and snippets.

@angelorocha
Created July 5, 2021 16:53
Show Gist options
  • Save angelorocha/85234d7bf769811c9278ed513e98fe32 to your computer and use it in GitHub Desktop.
Save angelorocha/85234d7bf769811c9278ed513e98fe32 to your computer and use it in GitHub Desktop.
Convert CSV file in array
<?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