note 68018 added to function.print-r
| From: | shmohel at gmail dot com | Date: | Mon, 10 Jul 2006 14:14:15 +0000 |
| Subject: | note 68018 added to function.print-r | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-114634@lists.php.net to get a copy of this message | ||
In debugging my sites, I always find it useful to use print_r() to display the contents of my
arrays. However, they would appear on the site without linebreaks, and I would need to View Source
in order to properly see the array structure.
I built this simple little function that will take the contents of an array and return them on
screen with linebreaks and indentations.
Feel free to use and tweak as necessary.
<?php
function showarr($array){
$show="<div style='margin:5px; font:normal 10px Courier,Arial; text-align:left;
'>==========<br />\n";
function sharr($key,$input,$num){
$px=$num*15;
$retarr="<div style='margin-left:{$px}px; '>[{$key}] =>
'{$input}'</div>\n";
if(is_array($input)){
$num++;
foreach($input AS $skey=>$sval){
$retarr.=sharr($skey,$sval,$num);
}
$num--;
}
return $retarr;
}
$num=0;
foreach($array AS $key=>$val){
$show.=sharr($key,$val,$num);
}
$show.="==========</div>\n";
return $show;
}
?>
----
Server IP: 216.194.113.175
Probable Submitter: 63.240.121.48
----
X-Spam-Status: No, hits=3.3 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER,
HTML_MESSAGE autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.print-r.php
Edit -- http://master.php.net/note/edit/68018
Del: integrated -- http://master.php.net/note/delete/68018/integrated
Del: useless -- http://master.php.net/note/delete/68018/useless
Del: bad code -- http://master.php.net/note/delete/68018/bad+code
Del: spam -- http://master.php.net/note/delete/68018/spam
Del: non-english -- http://master.php.net/note/delete/68018/non-english
Del: in docs -- http://master.php.net/note/delete/68018/in+docs
Del: other reasons-- http://master.php.net/note/delete/68018
Reject -- http://master.php.net/note/reject/68018
Search -- http://master.php.net/manage/user-notes.php