`<pre>
<?php
$a = array (1, 2, array ("a", "b", "c"));
var_dump ($a);
?>
</pre>`

add a note User Contributed Notes
var_dump
andre at webkr dot de
04-Oct-2005 11:45
`var_dump prefixes the variable type with & if the variable has more than one reference.
This is only true for variables that are part of an array, not for scalar types.
Example:
<?php
$a['foo'] = 'other';
$a['bar'] = 'i_have_ref';
$b =& $a['bar'];
var_dump($a);
var_dump($b);
?>
Result:
array(2) {
["foo"]=>
string(5) "other"
["bar"]=>
&string(10) "i_have_ref"
}
string(10) "i_have_ref"`
Dennis Pallett
10-Aug-2005 12:57
`<?php
function show($data, $func = "print_r", $return_str = false){
ob_start();
$func($data);
$output = '<pre>'.htmlspecialchars(ob_get_contents()).'</pre>';
ob_end_clean();
if($return_str) return $output; else echo $output;
}
?>
From http://keithdevens.com/weblog/archive/2004/Jul/15/PHP.show
Works perfectly for me. Makes it extermely easy to view variables, arrays and objects.`
ospinto at hotmail dot com
07-Aug-2005 06:43
`Just created this neat class that dumps a variable in a colored tabular structure similar to the cfdump tag in Coldfusion. Very easy to use and makes it so much easier to see the contents of variable. For examples and download, visit http://dbug.ospinto.com`
As
30-Jun-2005 10:58
`The dumped variables don't have html entities encoded. So if your variable contains < in the data, your browser will see it as the start of an html tag. Additionally the dump has lots of => in it, which are also not escaped, although your browser does manage to figure out to display them as is. But they are errrors though.
Wrapping it in PRE doesn't help. Using the XMP tag will work, but it's a depreciated tag. I'm using it anyway, since it does what I need, and this function isn't (usually) used for production code anyway.
<?php
echo "<XMP>";
var_dump(get_defined_vars());
echo "</XMP>";
?>
XMP is your best bet, or use output control and the htmlspecialchars function.`
edwardzyang at thewritingpot dot com
20-Mar-2005 11:06
`If you're like me and uses var_dump whenever you're debugging, you might find these two "wrapper" functions helpful.
This one automatically adds the PRE tags around the var_dump output so you get nice formatted arrays.
<?php
function var_dump_pre($mixed = null) {
echo '<pre>';
var_dump($mixed);
echo '</pre>';
return null;
}
?>
This one returns the value of var_dump instead of outputting it.
<?php
function var_dump_ret($mixed = null) {
ob_start();
var_dump($mixed);
$content = ob_get_contents();
ob_end_clean();
return $content;
}
?>
Fairly simple functions, but they're infinitely helpful (I use var_dump_pre() almost exclusively now).`
dwatson at planandgrow dot com
10-Mar-2005 01:02
`To make sure to get the nice indenting of nested arrays, you may have to put html-<pre> tags around the var_dump():
Where $a is an array--
echo "<pre>";
var_dump($a);
echo "</pre>";`
anon
28-Jan-2005 03:31
`var_dump(get_defined_vars());
will dump all defined variables to the browser.`