Write Data to CSV File using PHP

fputcsv function

<?php

$data = [
    ['John', 25],
    ['Mary', 30],
    ['Robert', 42],
];

$fp = fopen('test.csv', 'wb');

foreach ($data as $item) {
    fputcsv($fp, $item);
}

fclose($fp);

Leave a Comment

Cancel reply

Your email address will not be published.