Print array to a file

Download File to server from URL
Create a CSV File for a user in PHP

problem statement

If you want to print an array to a file, follow the solutions provided below.

solution 1

Either var_export or set print_r to return the output instead of printing it.

You can then save $results with file_put_contents. Or return it directly when writing to file:

file_put_contents('filename.txt', print_r($b, true));

solution 2

Try following code.

$h = fopen('filename.txt', 'r+');
fwrite($h, var_export($your_array, true));
Download File to server from URL
Create a CSV File for a user in PHP
en English
X
Scroll to Top