Ever use PHP’s var_dump() or print_r() to debug what is going wrong with that $data you have ?
Well, this simple script acts as the above functions, yours first parameter is your data, and the second optional parameter is stoping the script or continuing on.
The ‘debug_backtrace()’ function will return which file call’s the dump function so you can easily track where your errors are coming from.
function dump($data = array(), $finish = TRUE) { list($referrer) = debug_backtrace(); $total = count($data); echo '<fieldset style="background: #fefefe !important; border:2px red solid; padding:5px">'; echo '<legend style="background:lightgrey; padding:5px;">'.$referrer['file'].' @ line: '.$referrer['line'].'</legend>'; echo '<pre>'; $l = 0; if($data) { foreach($data as $line => $value) { echo '<br /><strong>Debug #'.(++$l).' of '.$total.', Line: #'. $line .'</strong>:<br /> '; print_r($value); } } echo "
“;
echo “
“;
if($finish == TRUE) die;
}
View an example of this here;
http://codesnipp.it/code/1220