Home > Backend Development > PHP Tutorial > 如何讲二维数组写入txt文件

如何讲二维数组写入txt文件

WBOY
Release: 2016-06-13 13:40:09
Original
1565 people have browsed it

怎么讲二维数组写入txt文件

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
$total = array(array("address","age"));
$total[$name] = ...

Copy after login

数组定义和赋值是这个格式,怎么把数组的数据写入txt文件

------解决方案--------------------
PHP code
$arr = 你的数组;
$fn = '带保存的文件名';
foreach($arr as $name=>$row) {
  file_put_contents($fn, "$name,$row[address],$row[age]" . PHP_EOL, FILE_APPEND);
} <div class="clear">
                 
              
              
        
            </div>
Copy after login
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template