Question

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;
Was it helpful?

Solution

Or you could just use

$content=var_export($variable,true)
echo $content;

Reference: http://www.php.net/var_export

OTHER TIPS

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;
?>

var_export with return value set to true.

You can also use function calls

$result[] = var_export($class->function($otherClass->otherFunction['id']), true);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top