1

I'm trying to debug a drupal 7 site and print_r() the $variables variable, but its HUGE and crashes certain pages when there is alot of data in it. Is there a way to only output the first level of the array without outputting everything inside of it?

1

Devel is a great tool for debugging. It comes with krumo() function which works similar to print_r() but doesn't output everything, only up to certain depth (I think 3 or 4 levels).

  • i know about devel, but what if I didn't want to use that. how can I do it in pure php? is there a special function for it? – Patoshi パトシ May 7 '16 at 18:22
1

I faced a similar issue and found a raw solution, not very elegant nor easily usable in all cases, but it might help you:

  1. First use print_r(array_keys($variables)).
  2. Look at the result to locate which keys match your needs.
  3. Then for each one, say $var_x, use print_r($variables[$var_x])
  4. And if it's too heavy again, go to #1 replacing $variables by $variables[$var_x])... and so on!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.