print_r in drupal_set_message

This example will print our human readable information about the $_SESSION inside a drupal_set_message. You can replace the $_SESSION with any other variable or array (or object).

  1. drupal_set_message('<pre>'. print_r($_SESSION, true) .'</pre>');

If you liked this, you'll love my book, Master Drupal Module Development.

"..the must have drupal developers book"

Feeling stuck with Drupal 8 module dev?

Get the free 7 lesson course that will help you get started today without feeling overwhelmed.

  • Create Drupal modules with just a few commands using the Drupal Console
  • Create custom pages
  • Create custom blocks
  • Create admin forms
  • Demystify routers and controllers
  • Bonus material

Find out more


I think the Drupal code standards always has TRUE/FALSE in uppercase. I know both work but when checking my work with the coder module I don't like it to complain about little things.

I use this technique to figure out what's up very often. Usually to make sure what should be there is.

Just what I needed. Thanks.

Add new comment