Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

print_r

Description

The print_r of Variable Handling for PHP prints human-readable information about a variable.

Syntax

print_r(
    mixed $value,
    bool $return = false
): string|bool

Parameters

value

The expression to be printed.

return

If you would like to capture the output of print_r(), use the return parameter. When this parameter is set to true, print_r() will return the information rather than print it.

Return

If given a string, int or float, the value itself will be printed. If given an array, values will be presented in a format that shows keys and elements. Similar notation is used for objects.

When the return parameter is true, this function will return a string. Otherwise, the return value is true.

Examples

1 · value · bool

<?

$value = false;

print_r($value);

?>

2 · value · int

<?

$value = 0;

print_r($value);

?>
0

3 · value · float

<?

$value = 0.0;

print_r($value);

?>
0

4 · value · string

<?

$value = "0";

print_r($value);

?>
0

5 · value · array

<?

$value = array(0, 1, array(0, 1));

print_r($value);

?>
Array
(
    [0] => 0
    [1] => 1
    [2] => Array
        (
            [0] => 0
            [1] => 1
        )

)

6 · value · object · standard class

<?

$value = new stdclass;
$value->var = 0;

print_r($value);

?>
stdClass Object
(
    [var] => 0
)

7 · value · object · custom class

<?

class myclass
{
    public $var;
}

$value = new myclass;
$value->var = 0;

print_r($value);

?>
myclass Object
(
    [var] => 0
)

8 · return · false

<?

$value = 0;
$return = false;

$output = print_r($value, $return);

//var_export($output);

?>
0

9 · return · true

<?

$value = 0;
$return = true;

$output = print_r($value, $return);

//echo $output;

?>
HomeMenu