Looking to Build/Redesign a Website or Blog ?

To speak to Rakshit, call +91 968 704 2303

Write Array in txt file with PHP

Hello Friends,

Every programmer knows how to interact with file handling functions like fopen, fwrite, fread and fclose. Also most of us are aware with writing variable values in text file by using fwrite file handling function. Today i face a situation where i need to write array in text file using php as i am interacting with XML-RPC and in that i can’t use any of echo,print_r or var_dump. So this might help you if you face such kind of situation. Below is the code for writing array in text file using fwrite() in PHP.

$val = print_r($array,true);
$fp = fopen('d:\data.txt','a+');
fwrite($fp, $val);

Let me know if you find any problem.

Thank You!



Leave a Reply

Your email address will not be published.