How to write php array in a file

Sometimes we want to store php array in file for debugging or examination purpose.
One way for this is to capture all the values (including array ) in buffer and later print on a file:
For example:

ob_start(); // Start buffering
print_r($arrValue); // Print the value of array. We can also use var_dump just as per our need.
$getValues = ob_get_clean(); // Capture the value in a php variable.
ob_end_clean();
// Write the conent in required file.
error_log(” Data ::”.$getValues.” \n\”, 3, “/path/to/destination/directory/log-file-name”);

Leave a Reply

Your email address will not be published. Required fields are marked *.

*
*
You may use these <abbr title="HyperText Markup Language">HTML</abbr> tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>