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

LVL 16
hankknightAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

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

Open in new window

0
ncooCommented:
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
0
Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

Beverley PortlockCommented:
LOL! Thanks ncoo - I thought I had put that in, obviously not.....
0
hankknightAuthor Commented:
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);
 
?
0
ncooCommented:
Try this:
ob_start();
 
$zzz=array('111','222',333);
var_dump($zzz);
 
$qqq = ob_get_clean();
echo $qqq;

Open in new window

0
ncooCommented:
What we're doing is using PHP output controls to catch the var_dump and setting the captured output to your qqq value.
0
hankknightAuthor Commented:
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)?
0
ncooCommented:
You could try: http://pear.php.net/package/Var_Dump

http://pear.php.net/package/Var_Dump/docs/latest/li_Var_Dump.html

I have never used it myself so can't comment on which method is faster.

It may also be worth looking at: http://uk2.php.net/manual/en/function.var-export.php

var_export() gets structured information about the given variable. It is similar to var_dump()  with one exception: the returned representation is valid PHP code.

$qqq = var_export($zzz,true);

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.