PHP中捕获var_dump的结果赋值给字符串

php文档中对缓冲区有这样的描述:

As with anything that outputs its result directly to the browser, the output-control functions can be used to capture the output of this function, and save it in a string

那我们是不是能利用这一点将var_dump的结果捕获且赋值给某变量呢?

测试代码:

<?php
ob_start();
var_dump($someVar);
$result = ob_get_clean();
?>

 

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据