DEV Community

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

Posted on • Originally published at wallacemaxters.com.br

Simply way to write PHP output in Javascript console.log

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)