note 42233 deleted from function.print-r by aidan

From: Date: Mon, 11 Oct 2004 13:06:58 +0000
Subject: note 42233 deleted from function.print-r by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-78340@lists.php.net to get a copy of this message
Note Submitter: phpemail at supernaut dot org ---- 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

« previous php.notes (#78340) next »