Are there any best practices for handling logs in PHP, specifically in relation to print_r() output?

When using print_r() to output logs in PHP, it's important to properly handle the formatting and readability of the logs. One common issue is that the output can be difficult to read, especially for large arrays or nested data structures. To improve the readability of print_r() output, you can use the <pre> HTML tag to preserve formatting and display the output in a more structured way.

// Example code snippet to handle logs in PHP using print_r() with improved formatting
$logData = array(&#039;key1&#039; =&gt; &#039;value1&#039;, &#039;key2&#039; =&gt; array(&#039;subkey1&#039; =&gt; &#039;subvalue1&#039;, &#039;subkey2&#039; =&gt; &#039;subvalue2&#039;));

// Output log data with improved formatting using &lt;pre&gt; tag
echo &#039;&lt;pre&gt;&#039;;
print_r($logData);
echo &#039;&lt;/pre&gt;&#039;;