note 42233 added to function.print-r
| From: | phpemail at supernaut dot org | Date: | Sun, 09 May 2004 04:24:22 +0000 |
| Subject: | note 42233 added to function.print-r | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-69359@lists.php.net to get a copy of this message | ||
Hi,
This is a function that prints an array so that it's readble when viewed in a web browser, with
array values indented.
<?php
function print_r_html($r) {
foreach ($r as $key => $val) {
if (is_array($val)) {
echo "[$key] = An Array:<BLOCKQUOTE>";
print_r_html($val);
echo "</BLOCKQUOTE></P>";
} else {
echo "[$key] = '$val'<BR>";
} #end if stmt
}
} # end function print_r_html
?>
<sidebar/irrelevancy>
Something like this might already exist as a PHP function, but I didn't find it quickly when I
searched for it, and since I'm just learning the language I figured I'd detour and call it
a learning project for me, and share it cuz it seems like something that might be handy.
I only tested the recursive thing slightly cuz I don't need it for what I'm working on
now, so sorry if it doesn't hold water. I'm sure it can be done better in other ways, and
I can think of a dozen ways to add flexibility to it, but I figure simple's rarely wrong, so
such is.
</sidebar>
anyhoo,, cheers,
:)ben
----
Manual Page -- http://www.php.net/manual/en/function.print-r.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+42233
Delete -- http://master.php.net/manage/user-notes.php?action=delete+42233&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+42233&report=yes
Search -- http://master.php.net/manage/user-notes.php