将数组保存到文件 - 仅限值

时间:2017-11-22 08:11:23

标签: php

我正在使用这种方法:

$s = array("one","two","three");
file_put_contents('file.txt', print_r($s, true)."\n");

file.txt输出为:

Array
(
    [0] => one
    [1] => two
    [2] => three
)

我希望输出只是这样的值:

one
two
three

怎么可以这样做?

1 个答案:

答案 0 :(得分:2)

试试这个

$s = array("one","two","three");
file_put_contents('file.txt', implode("\n",$s));

查看现场演示:https://eval.in/904966

输出为

one
two
three