Reputation: 1475
Is is possible I can assign output of var_dump($var)
to a variable? As a default behavior, var_dump() just prints output on screen. I want to append or assign its output to other variable and then output that later on. Like:
$a = true;
$b = var_dump($a);
echo $b;
Upvotes: 4
Views: 4666
Reputation: 114
var_export with return value set to true.
You can also use function calls
$result[] = var_export($class->function($otherClass->otherFunction['id']), true);
Upvotes: 0
Reputation: 777
Or you could just use
$content=var_export($variable,true)
echo $content;
Reference: http://www.php.net/var_export
Upvotes: 10
Reputation: 1602
One way would be to do it in the following way, using the output buffering.
<?php
ob_start();
var_dump($a);
$result = ob_get_clean();
echo $result;
?>
Upvotes: 3