Last active
April 12, 2016 16:44
-
-
Save AntonTrollback/8946d3959a6adf17ead4 to your computer and use it in GitHub Desktop.
log php to browser console
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function logga() { | |
echo '<script>console.log('; | |
foreach (func_get_args() as $index => $arg) { | |
$type = gettype($arg); | |
if ($type === 'boolean') { | |
$arg = $arg ? 'true' : 'false'; | |
} elseif ($type === 'string') { | |
$arg = '"' . $arg . '"'; | |
} elseif ($type === 'array' || $type === 'object') { | |
$arg = json_encode($arg); | |
} elseif ($type === 'NULL' || $type === 'unknown type') { | |
$arg = 'null'; | |
} | |
if ($index != 0) { | |
echo ', '; | |
} | |
echo $arg; | |
} | |
echo ')</script>'; | |
} | |
// Usage | |
logga($something, $something_else); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment