Am joining multiple CSV files using a script below and writing a file.
How can I write the same content and create two different files with different file names?
/////////// ---- JOINING THE FILES ---- ///////////
$nn = 0;
foreach (glob("*.csv") as $filename) {
if (($handle = fopen($filename, "r")) !== FALSE) {
while (($data = fgetcsv($handle, 0, ",")) !== FALSE) {
$c = count($data);
//$csvarray[$nn][] = $filename;
for ($x=0;$x<$c;$x++)
{
$csvarray[$nn][] = $data[$x];
}
$nn++;
}
fclose($handle);
}
}
$fp = fopen("../newfile.csv", "w");//output file set here
foreach ($csvarray as $fields) {
fputcsv($fp, $fields);
}
// Need to create another file with the same contents here!!
fclose($fp);