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

2 2

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

Top comments (0)

Heroku

This site is powered by Heroku

Heroku was created by developers, for developers. Get started today and find out why Heroku has been the platform of choice for brands like DEV for over a decade.

Sign Up

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay