Append rows to CSV file using PHP

You can use this PHP code snippet to append data/rows to CSV file.


									<?php

function AppendCSV($csvPath, $rows) {
	$fh = fopen($csvPath, 'a');
	foreach ($rows as $row) {
		fputcsv($fh, $row);
    }
	fclose($fh);
}

// Example:
$rows = array(
	array("Randy", "45"),
	array("Ray", "37")
);
AppendCSV("sample.csv", $rows);

?>
								

paterson23

Always ready to learn new things.

Comments (0)

No Comments Yet.