Home > Backend Development > PHP Tutorial > 怎么将print_r()的输出存入变量

怎么将print_r()的输出存入变量

WBOY
Release: 2016-06-13 10:46:08
Original
1410 people have browsed it

如何将print_r()的输出存入变量
希望将多维数组转换为类似print_r()输出的格式,用了var_export()和var_dump()都是直接输出了

不止可否将输出的内容接受到某个变量,或者将数组以类似的格式转化为字符串的方法。

不胜感激。

------解决方案--------------------
print_r 和 var_export 都可以将第二个参数设为 true (默认是 false) 来使结果保存大变量中

PHP code
$a = array(1,2,3);$r1 = print_r($a, 1);$r2 = var_export($a, 1);echo $r2;echo $r1;<div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template