Debug php code on browser
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>";
}
-
In the line that you need to console log, add this code
debug_to_console(“Test”);
-
If what you need to debug is an object, you can also log it via
debug_to_console(json_encode($foo));
Open developer browser, and you should be able to see the console.log of the php object.

About
Experience in software development, consulting services, and technical product management. Understanding of business and technology with an MBA in Finance and a Master's degree in Computer Science. Certified in AWS, GCP and Kubernetes with experience in building banking products from scratch and serving as a charismatic leader.