Friday, June 3, 2016

HOW TO PRINT/ECHO/WRITE ARRAY VALUES IN FILE - PHP

Generally it is very easy to write some string in file using php. But some times, we may required to write arrays in file using php. The situation may arise when we required to check API input values, post method values etc..
HOW TO PRINT/ECHO/WRITE ARRAY VALUES IN FILE
Add HOW TO PRINT/ECHO/WRITE ARRAY VALUES IN FILE

General method to write string in php is,
$text = "Hai how are you";
file_put_contents("test.txt",$text);
After executing above code, you will get an output as "Hai how are you" in the file.

How to write array values in a file?

$a = array('1','2','3','4','5');
file_put_contents("test.txt",print_r($a,true));
Execute above code and see the array values printed in the file. If you have any queries or suggestion related this post, feel free to comment below.

No comments:

Post a Comment