When you want to debug with PHP logging, or an AJAX request error. We generally write information to a specified file
Of The problem is then handled according to the appropriate information.
For example, I like to use Ajax do not get data, in the PHP script and add the following code
Copy CodeThe code is as follows:
$fp = fopen ('./a.txt ', ' a+b ');
Fwrite ($fp, $content);
Fclose ($FP);
However, there is a problem here. That is $content is an array to do?
You might say, I loop the output. What about multidimensional arrays?
I just need to be so tired to debug.
Here you can use Var_export ().
This function returns the structure information about the variable passed to the function, which is similar to Var_dump (), unlike
The representation of its return is a valid PHP code.
You can return the representation of a variable by setting the second argument of the function to TRUE.
Copy CodeThe code is as follows:
$fp = fopen ('./a.txt ', ' a+b ');
Fwrite ($fp, Var_export ($content, true));
Fclose ($FP);
Note The second parameter of Var_export () needs to be set to true to indicate that the return value is obtained. or the direct output.
Also, if your $content is just an array, and it doesn't contain anything else.
You can also use Print_r ()
Similarly, the second parameter of Print_r () is also set to True
Copy CodeThe code is as follows:
$fp = fopen ('./a.txt ', ' a+b ');
Fwrite ($fp, Print_r ($content, true));
Fclose ($FP);
Parsing how to write an array variable to a file in PHP