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,010
  • 13
  • 100
  • 141
Web_Designer
  • 68,768
  • 89
  • 200
  • 259

2 Answers2

112

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
  • 81,083
  • 20
  • 131
  • 150
6
$var_info = print_r($var, true);
Elijan Sejic
  • 1,406
  • 1
  • 8
  • 11