print_r() more responsibly

As print_r() spits ugly markup onto the page, running it on live sites is not advised.

print_r() is for debugging, and the best place to debug things is in a staging environment. As print_r() spits ugly markup onto the page, running it on live sites is not advised—although possible if you don’t have alternatives.

If you do need to run a var_dump() on a live site, you can do it slightly more responsibly by enclosing the results in a hidden div:

<div style="display: none;"><?php var_dump( $testvar ); ?></div>

You can then view the page source (using your browser’s “View Page Source” feature or its development tools feature set) to see the results of the var_dump() without impacting live users.