In javascript, you can console.log(‘whatever”) in your browser for troubleshooting. However, in php code, a little bit trick is required to do so. Here are the steps:

function debug_to_console($data) {
$output = $data;
if (is_array($output))
$output = implode(',', $output);

echo "<script>console.log('Debug Objects: " . $output . "' );</script>";

2. In the line that you need to console log, add this code


3. If what you need to debug is an object, you can also log it via


Open developer browser, and you should be able to see the console.log of the php object.

Originally published at on December 4, 2019.