Better PHP Logging

If you are doing any kind of PHP development you will no doubt need to log out some values. Unlike JavaScript, logging out to the browser developer tools isn’t possibly as PHP is a server side language.

Thankfully with a tiny bit of markup wrapping your var_dump or print_r statement you can easily read information about the variable.


<?php

echo "<pre>"; 
var_dump($your_variable); 
echo "</pre>";

?>

Or


<?php

echo "<pre>"; 
print_r($your_variable); 
echo "</pre>";

?>

Want to become a better web developer?

Join over 25,000 other developer & designers who get awesome links to the best news and articles each week delivered directly to their inbox.

1 Comment

  1. In my WordPress projects, I use a function called ‘pretty’ that wraps a parameter in the pre tags and does print_r. When I need to see what’s happening, I call it like pretty($array). Super convienent.

This post currently has one response. What do you think?

You can use basic HTML when posting code, please turn all < characters into &lt; or > into &gt;
If the code is multi-line, use <pre><code></code></pre>

Leave a Reply

Your email address will not be published. Required fields are marked *