Language
日本語
English

Caution

JavaScript is disabled in your browser.
This site uses JavaScript for features such as search.
For the best experience, please enable JavaScript before browsing this site.

PHP Dictionary

  1. Home
  2. PHP Dictionary
  3. var_dump() / print_r() / var_export()

var_dump() / print_r() / var_export() Since: PHP 4(2000)

A debugging function that outputs the type and value of a variable. It is an essential tool for verifying behavior during development.

Syntax

// Outputs the type and value of a variable in detail.
var_dump($value1, $value2, ...);

// Outputs an array or object in a human-readable format.
print_r($value, $return);

// Outputs a variable in a format that is valid as PHP code.
var_export($value, $return);

Function List

FunctionDescription
var_dump($value, ...)Outputs the type, value, and element count of a variable in detail. You can pass multiple variables at once. Returns no value.
print_r($value, $return)Outputs an array or object in a human-readable format. If you pass true as the second argument, it returns the output as a string instead of printing it.
var_export($value, $return)Outputs a variable as a string that is valid PHP code. If you pass true as the second argument, it returns the output as a string instead of printing it.

Sample Code

<?php
// var_dump() displays the type and value in detail.
var_dump(42);          // Outputs: int(42)
var_dump(3.14);        // Outputs: float(3.14)
var_dump("PHP");       // Outputs: string(3) "PHP"
var_dump(true);        // Outputs: bool(true)
var_dump(null);        // Outputs: NULL

// Inspect the structure of an array.
$user = ['name' => 'Taro', 'age' => 25, 'active' => true];
var_dump($user);

// print_r() outputs in a readable format.
$colors = ['red', 'blue', 'green'];
print_r($colors);

// Passing true as the second argument returns the output as a string.
$output = print_r($colors, true);
echo "Array contents: " . $output;

// var_export() outputs in a format valid as PHP code.
$config = ['debug' => true, 'version' => '2.0'];
var_export($config);

// Example of storing the return value of var_export() in a variable.
$code = var_export($config, true);
file_put_contents('config_cache.php', '<?php return ' . $code . ';');

// Inspecting multiple variables at once with var_dump().
$name = "Hanako";
$score = 95;
$passed = true;
var_dump($name, $score, $passed);

Notes

var_dump() is the most reliable output function for debugging. With echo or print_r(), values like false, null, and empty strings appear as blank — but var_dump() displays them accurately along with their types. Always use var_dump() when type information is important for debugging.

print_r() displays the structure of arrays and objects in a readable way, making it convenient for a quick look at the contents of your data. Passing true as the second argument captures the output and returns it as a string, which is also useful for writing to logs.

var_export() outputs a string that is valid as PHP code, so it can be used for generating cached configuration files. Note that it does not support resource types or closures. If you want to capture output using output buffering, see ob_start().

If you find any errors or copyright issues, please .