Skip to content

Instantly share code, notes, and snippets.

@omar-faruk-sust
Created August 2, 2022 04:05
Show Gist options
  • Save omar-faruk-sust/98fc3646ee567af58f8a8d19b190e2a5 to your computer and use it in GitHub Desktop.
Save omar-faruk-sust/98fc3646ee567af58f8a8d19b190e2a5 to your computer and use it in GitHub Desktop.
<?php
$list[] = array ("name","gender","age");
$values = [
array("Hello","M","21"),
array("Syed","M","30"),
array("Rishat","F","25")
];
for($i = 0; $i < 20000; $i++) {
$list[] = $values[rand(0,2)];
}
$filename = __DIR__ . "/files/" . "myCSV.csv";
if(file_exists($filename)) {
unset($list[0]);
$handle = fopen($filename, "a");
foreach ($list as $fields) {
fputcsv($handle, $fields);
}
fclose($handle);
} else {
$fp = fopen($filename, 'w');
foreach ($list as $fields) {
fputcsv($fp, $fields);
}
fclose($fp);
}
echo "done";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment