PHP中 VAR_DUMP()
VAR_DUMP($value) 输出 $value 的结构信息。不过有个小问题
Manual 中的 tips: 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 (for example).
大致意思是 会直接输出结果到浏览器 可以使用{输出控制函数}将其捕捉保存到字符串
函数如下:
funciton varDumpToString($value)
{
ob_start();
var_dump($str);
$result = ob_get_clean();
return $result;
}
为什么要这样 对比一下程序就可以明白
$value = "hello";
//使用var_dump()
echo "Type of the value is:" .var_dump($value);
echo var_dump($value) ."Type of the value is:"
//两条命令都会输出 string(5)"hello"Type of the value is:
//怎么办 使用 varDumpToString($value);
echo "Type of the value is:" . varDumpToString($value);
//见证奇迹的时刻
//输出: Type of the value is:string(5)"hello"
浙公网安备 33010602011771号