我想在此输出中显示新的行和缩进
$a = array(1,2,3,4);
print_r($a);
Run Code Online (Sandbox Code Playgroud)
所以不是这样的:
Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 )
Run Code Online (Sandbox Code Playgroud)
我会得到这样的东西:
Array (
[0] => 1
[1] => 2
[2] => 3
[3] => 4
)
Run Code Online (Sandbox Code Playgroud)
通过使用HTML <pre>标记.还记得传递true第二个参数print_r()
echo '<pre>' . htmlentities(print_r($a, true)) . '</pre>';
Run Code Online (Sandbox Code Playgroud)
同样正如@cHao所指出的,如果你<pre>在数据中发生任何标记,你需要通过htmlentities()或传递结果htmlspecialchars().
我建议使用HTML <pre>标签(预格式化):
echo "<pre>";print_r($a);echo"</pre>";
Run Code Online (Sandbox Code Playgroud)
编辑:
要连接输出,必须将print_rto 的第二个参数设置true为返回值而不是回显它:
echo "<pre>" . print_r($a,true) . "</pre>";
Run Code Online (Sandbox Code Playgroud)