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)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more