Normally print_r($var) will display data on the screen. Is there a way to redirect (capture) the output of print_r($var) to a file? i.e. The data will be stored in a file instead of displaying it on the screen.
You could try turning on output buffering before you call print_r, then use ob_get_contents() to store the buffer in a string. From there, simply write to the file.
Hope this helps 😉