📅  最后修改于: 2023-12-03 15:18:20.834000             🧑  作者: Mango
print_r()函数是PHP的一种调试工具,它用于打印变量的相关信息,包括类型、值等。它可以很方便的打印数组、对象等复杂类型的变量。
print_r ( mixed $expression [, bool $return = false ] ) : mixed
参数:
mixed $expression
: 打印的变量。bool $return
(可选):默认是false,如果设置为true,则会返回打印内容,而不是输出到屏幕上。返回值:
打印数组:
<?php
$array = array('a', 'b', 'c');
print_r($array);
?>
输出:
Array
(
[0] => a
[1] => b
[2] => c
)
打印对象:
<?php
class MyClass {
public $public = 'Public';
protected $protected = 'Protected';
private $private = 'Private';
function printHello() {
echo $this->public;
echo $this->protected;
echo $this->private;
}
}
$obj = new MyClass();
print_r($obj);
?>
输出:
MyClass Object
(
[public] => Public
[protected:protected] => Protected
[private:MyClass:private] => Private
)