Home > php教程 > php手册 > body text

php将数组转换成csv格式文件输出的方法,

WBOY
Release: 2016-06-13 09:12:09
Original
833 people have browsed it

php将数组转换成csv格式文件输出的方法,

本文实例讲述了php将数组转换成csv格式文件输出的方法。分享给大家供大家参考。具体实现方法如下:

<&#63;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");
&#63;>
Copy after login

希望本文所述对大家的php程序设计有所帮助。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!