Print_r displaying
I use the PHP function print_r quite a bit when debugging my PHP code. It's very handy to quickly see what is inside my arrays with this function. It's easy to use print_r, as you can see from the following example:
<?php print_r($myArray); ?>
The problem with the above code is that most of the time I am using PHP print_r's function in an HTML document. What this means is that the formatting of the output will be compressed and hard to read. The reason for this is because print_r uses new line characters and not br tags to separate lines. Below is an example of what I mean:
Reading your print_r code can be a little harder when the formatting looks like the above. There is a little trick that we can do to fix the problem.
<?php echo '<pre>'; print_r($myArray); echo '</pre>'; ?> ?>
By placing our print_r code within pre tags, our formatting will look a lot nicer. This is because our new line characters are now preserved in our HTML document and the following is now what is shown.