PHP » I/O » print_r()

Syntax:
string print_r(mixed var [, bool return])
var
Variable to print.
return
If set to TRUE, a string is returned instead of printing the variable.

Prints a variable in readable form.

print_r() prints a variable in a form that is easy to read. This is especially useful while debugging, to print out arrays. As of PHP 4.3.0, there is an optional parameter that makes print_r() return a string instead of directly outputting the result.

Examples

Code:
<pre>
<?php

$array1 = array(
   "un" => "one",
   "deux" => "two",
   "trois" => "three");

print_r($array1);

?>
</pre>
Output:
Array
(
   [un] => one
   [deux] => two
   [trois] => three
)
Explanation:

This example shows how print_r() formats the output of an array. If not used together with the <pre> html tag, the elements will show up all on one line, making the output significantly less readable.

See Also: