programmatore-siena-php

Trasformare un array in formato CSV

function array2csv(array &$array){
    if(count($array)==0){
        return null;
    }
    ob_start();
    $df = fopen("php://output", 'w');
    foreach($array as $row){
        fputcsv($df, $row);
    }
    fclose($df);
    return ob_get_clean();
}