Skip to content

Instantly share code, notes, and snippets.

@mcgrew
Created February 15, 2011 15:54
Show Gist options
  • Save mcgrew/827687 to your computer and use it in GitHub Desktop.
Save mcgrew/827687 to your computer and use it in GitHub Desktop.
Debugging function for printing a php array in a readable format
<?php
function print_array($array)
{
echo "<div style=\"font-family: 'Courier New', Courier, monospace; font-size: 12px;\">\n";
print_array_recursive($array, '');
echo "</div>\n";
}
function print_array_recursive($array, $prefix)
{
foreach ($array as $k=>$v)
{
if (is_array($v))
{
echo $prefix.$k.' =&gt; '."<br>\n";
print_array_recursive($v, $prefix."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
}
else
{
echo $prefix.$k.' =&gt; '.$v."<br>\n";
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment