Skip to content

Instantly share code, notes, and snippets.

@jpalala
Created December 23, 2023 00:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpalala/8b3499f55bba9a71120b3dc871c754e6 to your computer and use it in GitHub Desktop.
Save jpalala/8b3499f55bba9a71120b3dc871c754e6 to your computer and use it in GitHub Desktop.
simple helper
<?php
function csv_write($filename, $data){
$fp = fopen($filename, 'w');
foreach ($data as $fields) {
fputcsv($fp, $fields);
}
fclose($fp);
}
function csv_read($filename){
$row = 1;
if (($handle = fopen($filename, "r")) !== FALSE) {
$data = [];
$columnnames = fgetcsv($handle, 1024);
while ($rows = fgetcsv($handle)) {
$arr = array();
$row = array_combine($columnnames, $rows);
$data[] = $row;
}
return $data;
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment