Encodera

Thanks for reading!

Donate to the site — we work hard for you.

PHP reference

print_r

Prints a value in a readable form.

Syntax

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

Parameters

ParameterTypeDescription
$valuemixedThe value to show.
$returnboolOptional. `true` returns the text instead of printing it.

Return value

string|true`true`, or a string when the second argument is set.

Examples

An array in a readable form:

<?php
 
print_r(['name' => 'Anna', 'tags' => ['php', 'sql']]);

Output:

Array
(
    [name] => Anna
    [tags] => Array
        (
            [0] => php
            [1] => sql
        )
 
)

Notes

Unlike var_dump(), types are not shown: 1, '1' and true look the same. On a page wrap the output in a pre tag, otherwise the line breaks vanish.

See also

  • var_dump — Prints the type and the value — for debugging.
  • var_export — Prints a value as PHP code.
  • json_encode — Converts a value to a JSON string.

Related recipes

In the tutorial

  • Errors and debugging — The kinds of PHP errors, error display settings, the log, turning warnings into exceptions and debugging techniques.

Thanks for reading!

Donate to the site — we work hard for you.