How do I create code snippets for vscode for "print_r" that outputs the contents of the variable passed to it, along with the filename ,line number

309 views Asked by At

How do I create code snippets for vscode for "print_r" that outputs the contents of the variable passed to it, along with the filename and line number of the file where the function is called and Also want proper format print in output screen.

$data = array("Volvo", "BMW", "Toyota");
print_r($data);

I want output Like this : Myname FileNmae lineNumber data

sample output image

1

There are 1 answers

2
dev_mustafa On

Here is how you can achieve it. You need to pass your name as parameter to the function:

function printCustom($name)
{
    $data = array("Volvo", "BMW", "Toyota");
    print_r(
        $name ." ". basename(__FILE__) ." ". __LINE__." \n data :: "
    );

    print_r($data);
}


printCustom('Grimma');

Here is a working screenshot:

enter image description here