本文實例講述了php將數組轉換成csv格式文件輸出的方法。分享給大家供大家參考。具體實現方法如下:
<?php $sales = array( array('east','2005-01-01','2005-02-01',12.54), array('west','2005-01-01','2005-02-01',546.33), array('south','2005-01-01','2005-02-01',93.26), array('north','2005-01-01','2005-02-01',945.21), array('All Regions','--','--',1597.34) ); $fh = fopen('file.csv','w') or die("Can't open file.csv"); foreach ($sales as $sales_line) { if (fputcsv($fh, $sales_line) === false) { die("Can't write CSV line"); } } fclose($fh) or die("Can't close file.csv"); ?>
希望本文所述對大家的php程序設計有所幫助。