Every decent programmer has a print_r
or var_dump
wrapper they use, love and assign shortcut keys to, why don't we share our favourite ones.
I am using a simple one, here:
function dump($var = null) {
static $dumpId = 0;
if($dumpId == 0) {
echo '<style>pre {margin: 0px; text-align: left; color: #000; padding: 0px; font: 11px/17px Tahoma, Arial, "Lucida Grande", sans-serif; line-height: 17px; border: 3px solid #999; padding: 10px; margin: 10px; background: #eee;}</style>';
}
$argList = func_get_args();
$argNum = func_num_args();
for($i = 0; $i < $argNum; $i++) {
// if variable is array or object
echo '<pre>(Arg [' . $dumpId++ . ']) - ';
if(is_array($argList[$i]) or is_object($argList[$i])) {
print_r($argList[$i]);
} else {
// if other type of variable
var_dump($argList[$i]);
}
echo '</pre><br />';
}
}
It basically does nothing more than append some style to the output.
There are also some good ones on the PHP var_dump documentation page..