Ivan Zugec

Drupal Consultant

Replacement for print_r

How many times have you done the good old print_r($var); just to find out what’s in the variable?

I have been using the devel modules for age’s but it still surprises me what you can find if you just look at some code every now and then.

The devel module comes with a few great functions which you could use instead print_r();

kpr() function

Example:

kpr($node);

Output:

fig1_0.png

dpr() function

Example:

dpr($node);

Output:

fig2_0.png

dvr() function

Example:

dvr($node);

Output:

fig3_0.png

Looks better then the print_r output. If you know a better way leave a comment and let us know.

Comments

dereine's picture

Submitted by dereine on

Another cool thing, which does the devel module is dd($array);

This outputs the data into tmp/drupal_debug.txt, where you can get the data by using tail -f drupal_debug.txt.

Anonymous's picture

Submitted by Anonymous on

You can use also dsm() from Devel module which will show exactly the same output as kpr().

chx's picture

Submitted by chx on

i still consider var_export the most usable of them all, just pick up the output, drop it in a script and you can play with it. that's something only var_export output does.