note 43982 deleted from function.print-r by tomsommer
| From: | tomsommer@php.net | Date: | Sun, 11 Jul 2004 17:46:42 +0000 |
| Subject: | note 43982 deleted from function.print-r by tomsommer | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-73057@lists.php.net to get a copy of this message | ||
Note Submitter: cmott@newmexicostateuniversity.edu
----
Kudos to ben for his previous post of how to print an html-formatted array with sub-arrays. I like
it so much, I have included it in my file of necessary functions.
I wanted to post one of my changes to it that I personally find essential. I added the capability
to handle objects. If you use objects at all, this can become essential. I also cleaned up the
source formatting a little. Use and enjoy!
<?php
function print_r_html($r)
{
foreach ($r as $key => $val) {
if (is_array($val) or is_object($val))
{
echo "[$key] " . ((is_object($val)) ? "-> An Object:" : "= An
Array:") . "<BLOCKQUOTE>\n";
print_r_html($val);
echo "</BLOCKQUOTE></P>\n\n";
} else
{
echo "\t[$key] = '$val'<BR>\n";
} #end if stmt
}
} # end function print_r_html
?>
Btw, there are a number of possible improvements (source code indenting for one) that I will leave
as an exercise to anyone else.
CAM