php 将 print_r 结果放入变量

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5762515/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 22:24:53  来源:igfitidea点击:

putting print_r results in variable

php

提问by Web_Designer

In PHP I can say:

在 PHP 中,我可以说:

print_r($var);

What I can't do (at least I don't know how) is:

我不能做的(至少我不知道怎么做)是:

$var_info = print_r($var);

How can I accomplish the effect of putting the results of a print_rinside a variable?
PHP v5.3.5

如何实现将 a 的结果print_r放入变量中的效果?
PHP v5.3.5

回答by Shakti Singh

When the second parameter is set to TRUE, print_r() will return the information rather than print it

当第二个参数设置为 TRUE 时,print_r() 将返回信息而不是打印它

$var_info = print_r($var,true);

回答by Elijan Sejic

$var_info = print_r($var, true);