When developing you often need to verify the content of the variables you are working with but often the output is not formatted, and so hard to read.
Formatting the output every single time is just too much for me so I wrote this little function that does just that and accepts 4 parameters.
- The variable to print
- The text before so you can better read the output
- An left-margin parameter (Especially for wordpress as sometimes the output is behind the left navigation menu. But you might want to indent your output too so this could become an handy parameter)
- An exit flag. (Useful to print
$_POST
and$_GET
variables for instance or if you want to stop your code right after the output)
Here’s the snippet. All arguments are optionals except $var
of course!
function debug_print( $var, $name = '', $maring_left = '165', $exit = false ){
$name == '' ? $name = 'Variable Content:' : $name = $name;
echo '<pre style="margin-left: ' . $maring_left . 'px;"><strong style="font-size:1.5em;">' . $name . '</strong><br>';
print_r( $var, false);
echo '</pre>';
if( $exit ){
echo "--------------- \r\n<br>";
echo "Forced exit";
exit;
}
}
Leave a Reply