Link to home
Start Free TrialLog in
Avatar of hankknight
hankknightFlag for Canada

asked on

var_dump to variable

How can I var_dump to a variable?

This does NOT work
<?php
 
$zzz=array('111','222',333);
$qqq = var_dump($zzz);
 
?>

Open in new window

Avatar of Beverley Portlock
Beverley Portlock
Flag of United Kingdom of Great Britain and Northern Ireland image

<?php
 
$zzz=array('111','222',333);
$qqq = print_r($zzz);

echo $qqq;
?>
Avatar of ncoo
ncoo

Try:
<?php
 
$zzz=array('111','222',333);
$qqq = print_r($zzz,true);
 
echo $qqq;
?>

Open in new window

With print_r() you need to set the return parameter to true.

If you would like to capture the output of print_r(), use the return  parameter. If this parameter is set to TRUE, print_r() will return its output, instead of printing it (which it does by default).

http://uk2.php.net/print_r
LOL! Thanks ncoo - I thought I had put that in, obviously not.....
Avatar of hankknight

ASKER

Thank you all but this does not answer my question.  I am aware of print_r($zzz,true);

But print_r does NOT return all the same information as var_dump.

Is there anything like var_dump($zzz,true);
 
?
Try this:
ob_start();
 
$zzz=array('111','222',333);
var_dump($zzz);
 
$qqq = ob_get_clean();
echo $qqq;

Open in new window

What we're doing is using PHP output controls to catch the var_dump and setting the captured output to your qqq value.
ncoo, your idea is a hack and not what I am looking for.

Is the consensus that no PHP function is capable of doing what I am asking (without output buffering)?
ASKER CERTIFIED SOLUTION
Avatar of ncoo
ncoo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial