Debug value helper function

returns a human-readable version of a variable

function dval($val, $print=true, $method='var_export'){ 
    // dval = Debug a VALue -> easy to remember for me
    if ($method == 'var_export'){
        $r = var_export($val, true);
    else {
        $r = print_r($val, true);
    if ($print){ print "<pre>[[" . htmlspecialchars($r) . "]]</pre>"; }
    else { return "<pre>[[" . htmlspecialchars($r) . "]]</pre>"; }
Snippet Details

$v = array(1,2,3,array(1,2,3));
dval($v, 1, 'print_r');

Sorry folks, comments have been deactivated for now due to the large amount of spam.

Please try to post your questions or problems on a related programming board, a suitable mailing list, a programming chat-room,
or use a QA website like stackoverflow because I'm usually too busy to answer any mails related
to my code snippets. Therefore please just mail me if you found a serious bug... Thank you!

Older comments: