Web_Designer
Web_Designer

Reputation: 74610

putting print_r results in variable

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

Upvotes: 52

Views: 32933

Answers (2)

Elijan
Elijan

Reputation: 1416

$var_info = print_r($var, true);

Upvotes: 6

Shakti Singh
Shakti Singh

Reputation: 86416

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

$var_info = print_r($var,true);

Upvotes: 113

Related Questions