Home/Guides/PHP print_r vs var_dump

PHP Debugging Guides

PHP print_r vs var_dump

Compare print_r and var_dump for PHP debugging output and learn when each one is useful.

print_r() and var_dump() both show PHP values, but they optimize for different debugging needs.

Code examples

print_r($value);
var_dump($value);

print_r() is compact and readable for arrays. var_dump() includes types and lengths, which helps when debugging unexpected strings, booleans, and nulls.

Common errors

Do not leave raw debug output in production responses. It can reveal private data and break API output.

Try the PHP print_r Formatter.

FAQ

Which is easier to read?

print_r is usually easier for arrays. var_dump shows more type detail.

Should either be used in production?

No. Use proper logging in production code.

Related tools