How does PHP write array variables into files?

Source: Internet
Author: User

When logging with PHP, or Ajax request error, You Want To debug. We usually write information to a specified file. Then the problem is handled according to the corresponding information. For example, I like to add the following code $ fp = fopen ('. /a.txt ', 'a + B'); fwrite ($ fp, $ content); fclose ($ fp); however, there is a problem here. What if $ content is an array? You may say that I loop the output. What about multi-dimensional arrays? Is it so tiring for debugging. Here you can use var_export (). this function returns the structure information about the variables passed to this function. It is similar to var_dump (). The difference is that the returned representation is legal PHP code. You can set the second parameter of the function to TRUE to return the expression of the variable. $ Fp = fopen ('. /a.txt ', 'a + B'); fwrite ($ fp, var_export ($ content, true); fclose ($ fp); note var_export () the second parameter must be set to true to return the value. Otherwise, the output is directly. If your $ content is just an array and does not contain any other content, you can use print_r (), which is the same as print_r () the second parameter must also be set to true $ fp = fopen ('. /a.txt ', 'a + B'); fwrite ($ fp, print_r ($ content, true); fclose ($ fp );

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.