Replacement for print_r
Submitted by ivan on Wed, 09/09/2009 - 20:15
Output:
Output:
Output:
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:

dpr() function
Example:
dpr($node);
Output:

dvr() function
Example:
dvr($node);
Output:

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

Comments
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.
You can use also dsm() from Devel module which will show exactly the same output as kpr().
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.
Post new comment