(PHP 4, PHP 5, PHP 7, PHP 8)
print_r — 打印人类可读的变量信息
print_r() 以人类可读的方式显示变量的信息。
print_r()、var_dump()、var_export() 还将显示对象的 protected 和 private 属性。不会显示静态类成员。
示例 #1 print_r() 例子
<pre>
<?php
$a = array ('a' => 'apple', 'b' => 'banana', 'c' => array ('x', 'y', 'z'));
print_r ($a);
?>
</pre>以上示例会输出:
<pre>
Array
(
[a] => apple
[b] => banana
[c] => Array
(
[0] => x
[1] => y
[2] => z
)
)
</pre>
示例 #2 return 参数的例子
<?php
$b = array ('m' => 'monkey', 'foo' => 'bar', 'x' => array ('x', 'y', 'z'));
$results = print_r($b, true); // $results 包含了 print_r 的输出
?>注意:
When the
returnparameter is used, this function uses internal output buffering prior to PHP 7.1.0, so it cannot be used inside an ob_start() callback function.