Skip to content

Instantly share code, notes, and snippets.

@aurbano
Last active August 29, 2015 13:57
Show Gist options
  • Save aurbano/9686659 to your computer and use it in GitHub Desktop.
Save aurbano/9686659 to your computer and use it in GitHub Desktop.
PHP implementation of print_r to allow customization of the results
<?php
function print_json($json) {
if (is_array($json) || is_object($json)) {
echo "<table width=100%>";
$type = 'Array';
if(is_object($json)) $type = 'Object';
echo '<tr><td colspan=2 style="background-color:#333333;">
<strong><font color=white>'.$type.'</font></strong>
</td></tr>';
foreach ($json as $k => $v) {
echo '<tr><td valign="top" style="background-color:#F0F0F0;">';
echo '<strong>'.$k.'</strong></td><td>';
print_json($v);
echo "</td></tr>";
}
echo "</table>";
return;
}
echo $json;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment