You are here: Blog » Code Snippets » print_r pre

print_r pre


When you are using a print_r in php, it’s a very good idea to remember the print_r pre combo (ie wrap the print_r in a pre tag). The difference being that using pre will allow you to understand the output as it will be preformatted in a way that is easy for humans to see what is going on.

The Code

Suppose you start off with an array as follows


If you use print_r without wrapping in a pre tag, for example

Your output will look like this


That’s hard to read. However if you wrap the print_r in a pre tag, like so

Your output will look like this


Much better. I hope it comes in handy and would love to hear from you if it does.

photo credit: kjetikor via photopin cc

This entry was posted in Code Snippets and tagged by .

Author: justin saad

Justin Saad is first and foremost a husband and a father of four. He is also a web developer and designer who has been making websites for over twenty years. His company is called The Motech Network and his website is In addition to building websites, Justin makes WordPress plugins and likes writing tutorials to help others learn about various aspects of web development.

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">