Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and exploring the core foundations for app libraries.
Do more with
<?php
$handle = fopen("input.csv", "r");
$handle2 = fopen("output.csv", "r");
//We'll write the output to a third file;
$outhandle = fopen("newoutput.csv", "w");
//Write first 4 lines of output into new output file
$row = 1;
while (($data = fgetcsv($handle2, 1000, ",")) !== FALSE && $row < 5) {
$csvRow = implode(',', $data);
fwrite($outhandle, $csvRow);
$row++;
}
while (($data = fgetcsv($handle2, 1000, ",")) !== FALSE && while (($inputdata = fgetcsv($handle, 1000, ",")) !== FALSE) {
$outdata = array();
//push the first 12 records of output.csv into new output
for ($i=0; $i <=11; $i++) {
$outdata[$i] = $data[$i];
}
//push data from input.csv from 13th column onwards.
foreach($inputdata as $val) {
array_push($outdata, $val);
}
//Now create the string to be written to output file
$csvRow = implode(',', $outdata);
fwrite($outhandle, $csvRow);
}
fclose($outhandle, $handle, $handle2);
?>
Premium Content
You need an Expert Office subscription to comment.Start Free Trial