Last active
September 9, 2022 15:00
-
-
Save Avi-E-Koenig/d0317bb35fcf4bcd0b32696d5d8675fc to your computer and use it in GitHub Desktop.
Basic output to console of object
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
<?php | |
function echoPrettyJson($variable,$key) | |
{ | |
//pseudo | |
if($production) return; | |
try { | |
$key_name = $key ? $key : 'output'; | |
$content = new stdClass(); | |
$content->{$key_name} = $variable; | |
echo '<pre>' . json_encode($content, JSON_PRETTY_PRINT) . '</pre>'; | |
} | |
//catch exception | |
catch (Exception $e) { | |
echo 'Message: ' . $e->getMessage(); | |
} | |
} | |
function echoAsJSConsole($variable,$key) | |
{ | |
//pseudo | |
if($production) return; | |
try { | |
$key_name = $key ? $key : 'output'; | |
$content = new stdClass(); | |
$content->{$key_name} = $variable; | |
echo '<script>console.log(' . json_encode($content, JSON_PRETTY_PRINT) . ');</script>'; | |
} | |
//catch exception | |
catch (Exception $e) { | |
echo 'Message: ' . $e->getMessage(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment