Is there a pretty print for PHP?


Question

I'm fixing some PHP scripts and I'm missing ruby's pretty printer. i.e.

require 'pp'
arr = {:one => 1}
pp arr

will output {:one => 1}. This even works with fairly complex objects and makes digging into an unknown script much easier. Is there some way to duplicate this functionality in PHP?

1
110
7/22/2009 8:52:41 PM

Accepted Answer

Both print_r() and var_dump() will output visual representations of objects within PHP.

$arr = array('one' => 1);
print_r($arr);
var_dump($arr);
101
7/22/2009 8:54:32 PM

This is what I use to print my arrays:

<pre>
    <?php
        print_r($your_array);
    ?>
</pre>

The magic comes with the pre tag.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon