Created
December 23, 2023 00:31
-
-
Save jpalala/8b3499f55bba9a71120b3dc871c754e6 to your computer and use it in GitHub Desktop.
simple helper
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 | |
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