This function prints the text output to the console. If the $with_script_tags flag is set to true, the function also includes a JavaScript code fragment that outputs the string to the console.
function console_log($output, $with_script_tags = true) {
$js_code = 'console.log(' . json_encode($output, JSON_HEX_TAG) .
');';
if ($with_script_tags) {
$js_code = '<script>' . $js_code . '</script>';
}
echo $js_code;
}
console_log();