Garima Rajput
Garima Rajput

Reputation: 71

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

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

Upvotes: 0

Views: 399

Answers (1)

dev_mustafa
dev_mustafa

Reputation: 1111

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

Upvotes: 1

Related Questions