note 43982 added to function.print-r

From: Date: Sun, 11 Jul 2004 16:14:06 +0000
Subject: note 43982 added to function.print-r
Groups: php.notes 
Request: Send a blank email to php-notes+get-73054@lists.php.net to get a copy of this message
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 ---- Manual Page -- http://www.php.net/manual/en/function.print-r.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+43982 Delete -- http://master.php.net/manage/user-notes.php?action=delete+43982&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+43982&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#73054) next »