• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2230
  • Last Modified:

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

0
hankknight
Asked:
hankknight
  • 5
  • 2
  • 2
1 Solution
 
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 5
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now