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

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

WBOY
WBOYOriginal
2016-06-13 13:40:091567browse

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

PHP code
<!--

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

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


数组定义和赋值是这个格式,怎么把数组的数据写入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>
Statement:
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