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;
有帮助吗?

解决方案

Or you could just use

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

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

其他提示

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);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top