20th December 2007 - 3 minutes read time
When debugging PHP code the print_r can be useful if you want to know what an array or object contains. It will take any variable as input and will print off as much information as it can about that variable. The following code.
$array = array(1,34,6,2325,5,34,2);
echo "<pre>";
print_r($array);
echo "</pre>";
Will produce the following result.
Array
(
[0] => 1
[1] => 34
[2] => 6
[3] => 2325
[4] => 5
[5] => 34
[6] => 2
)
Notice the use of the pre tags. This is to allow the output to be properly formatted on screen, otherwise it looks messy. Of course you could just view source, but I find the formatted output easier on the eye. You could also write it out like this: