0

I'm using this approach:

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

the file.txt output is:

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

I want output to be just values like this:

one
two
three

How can be this done?

1
  • Please show us what you have tried. Commented Nov 22, 2017 at 8:12

1 Answer 1

2

Try like this

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

Check live demo : https://eval.in/904966

It outputs as

one
two
three
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.