Skip to content

Instantly share code, notes, and snippets.

@vihoangson
Created August 31, 2015 04:38
Show Gist options
  • Save vihoangson/414bd94f268a70171dd6 to your computer and use it in GitHub Desktop.
Save vihoangson/414bd94f268a70171dd6 to your computer and use it in GitHub Desktop.
<?php
function get_db_csv($file){
if(!$file){
$file = __DIR__.'/include/import.csv';
}
$row = 1;
if (($handle = fopen($file, "r")) !== FALSE) {
$csv = array();
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
if($row==1){
$column_name = $data;
}else{
foreach ($column_name as $key => $value) {
$db_csv[$data[0]][$value] = $data[$key];
}
}
$row ++;
}
fclose($handle);
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment