Create the CSV

function createCSV($csvData) { header( ‘Content-Type: application/excel’ ); header( ‘Content-Disposition: attachment; filename="data.csv"’ ); $fp = fopen( ‘php://output’, ‘w’ ); foreach ( $csvData as $row ) { fputcsv( $fp, $row, ‘,’ ); } fclose( $fp ); }

function createCSV($csvData) {
    
    header( 'Content-Type: application/excel' );
    header( 'Content-Disposition: attachment; filename="data.csv"' );

    $fp = fopen( 'php://output', 'w' );
    foreach ( $csvData as $row ) {
        fputcsv( $fp, $row, ',' );
    }

    fclose( $fp );
    
}

Share this Tutorial