note 109491 added to function.print-r
| From: | ReanimationXP at gmail dot com | Date: | Sun, 22 Jul 2012 12:49:18 +0000 |
| Subject: | note 109491 added to function.print-r | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-189350@lists.php.net to get a copy of this message | ||
If you're like me and just want an exact version of print_r() except formatted to HTML without
a bunch of bs, here you go.
The output is identical to print_r() but renders in HTML.
<?php
// Displays a multi-dimensional array as a HTML unordered lists.
function displayTree($array) {
$newline = "<br>";
foreach($array as $key => $value) { //cycle through each item in the array as key =>
value pairs
if (is_array($value) || is_object($value)) { //if the VALUE is an array, then
//call it out as such, surround with brackets, and recursively call displayTree.
$value = "Array()" . $newline . "(<ul>" . displayTree($value)
. "</ul>)" . $newline;
}
//if value isn't an array, it must be a string. output its' key and value.
$output .= "[$key] => " . $value . $newline;
}
return $output;
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 208.18.90.115
----
Manual Page -- http://www.php.net/manual/en/function.print-r.php
Edit -- https://master.php.net/note/edit/109491
Del: integrated -- https://master.php.net/note/delete/109491/integrated
Del: useless -- https://master.php.net/note/delete/109491/useless
Del: bad code -- https://master.php.net/note/delete/109491/bad+code
Del: spam -- https://master.php.net/note/delete/109491/spam
Del: non-english -- https://master.php.net/note/delete/109491/non-english
Del: in docs -- https://master.php.net/note/delete/109491/in+docs
Del: other reasons-- https://master.php.net/note/delete/109491
Reject -- https://master.php.net/note/reject/109491
Search -- https://master.php.net/manage/user-notes.php