Beautiful PHP dump to use in place of var_dump or print_r

PHP is pretty nice offering var_dump and print_r to let us dump the contents of a variable. The only problem is that is is abit ugly to look at and recursing into objects isn't always all that useful. Here is a solution.

Using the function is simple, you can call it without a label (as shown above) or add an extra label to the top level. The lable is handy when dumping multiple variables. You might place the name of the variable in the title bar at the first level.

If you would rather not display this information to the screen, you can capture it to a variable by passing FALSE in as the third parameter.

// dump to the screen

// dump to a variable

// dump to the screen and a variable

There are actually two additional parameters, but they are intended for internal use allowing this function to recurse down through all the levels of the variable you want dumped. You can examine the source code to see all the details.

Of course, you can change the CSS to match your needs or even take it out of the function all together and use your own CSS in its place.

View the source code.


Cross session variables that survive a reboot. >>
All content on this site is copyright ©2004-2023 and is not to be reproduced without prior permission.