52

In PHP I can say:

print_r($var);

What I can't do (at least I don't know how) is:

$var_info = print_r($var);

How can I accomplish the effect of putting the results of a print_r inside a variable?
PHP v5.3.5

Charles
  • 50,943
  • 13
  • 104
  • 142
Web_Designer
  • 72,308
  • 93
  • 206
  • 262

2 Answers2

113

When the second parameter is set to TRUE, print_r() will return the information rather than print it

$var_info = print_r($var,true);
Shakti Singh
  • 84,385
  • 21
  • 134
  • 153
6
$var_info = print_r($var, true);
Elijan
  • 1,406
  • 1
  • 8
  • 11