DEV Community

loading...
Cover image for Simply way to write PHP output in Javascript console.log

Simply way to write PHP output in Javascript console.log

wallacemaxters profile image Wallace Maxters Originally published at wallacemaxters.com.br ・1 min read

You can simply combine the printf and json_encode function to make this.

function console_log($data) {
    printf('<script>console.log(%s);</script>', json_encode($data));
}

console_log(['name' => 'Wallace Maxters']);
Enter fullscreen mode Exit fullscreen mode

Output:

image

Discussion (0)

pic
Editor guide