How to Write a PHP array formatted into a file

Source: Internet
Author: User
How to write the array (k1 & amp; gt; v1, k2 & amp; gt; v2) into a file. The content in the file is basically consistent with the following format: array (k1 & amp; gt; v1, k2 & amp; gt; v2) do not write a line with me. Is there a quick way? How to write the array (k1 => v1, k2 => v2) into a file. The content in the file is basically the same as the following format:

Array (
K1 => v1,
K2 => v2
)

Don't talk to me about writing a line. Is there a quick way?

Reply content:

How to write the array (k1 => v1, k2 => v2) into a file. The content in the file is basically the same as the following format:

Array (
K1 => v1,
K2 => v2
)

Don't talk to me about writing a line. Is there a quick way?

File_put_contents('result.txt ', var_export ($ categories, true ));

Okay, I have done it myself ..

In this case, file_put_contents('result.txt ', print_r ($ categories, true); or error_log (print_r ($ categories, true), 3, 'result.txt'); or.

Var_export is not in this format ~~~
Print_r should be used

File_put_contents('filename.txt ', print_r (array ($ k1 => $ v1, $ k2 => $ v2 ));

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.