Home > Backend Development > PHP Tutorial > How to convert an array into a csv format file and output it in php_PHP tutorial

How to convert an array into a csv format file and output it in php_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 10:03:48
Original
874 people have browsed it

How to convert an array into a csv format file and output it in php,

The example in this article describes how to convert an array into a csv format file and output it in php. Share it with everyone for your reference. The specific implementation method is as follows:

<&#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

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/967735.htmlTechArticleHow to convert an array into a csv format file using php. This article describes how to convert an array into a csv format file using php. Output method. Share it with everyone for your reference. The specific implementation methods are as follows...
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template