note 68018 deleted from function.print-r by philip
| From: | philip@php.net | Date: | Tue, 11 Jul 2006 06:34:45 +0000 |
| Subject: | note 68018 deleted from function.print-r by philip | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-114659@lists.php.net to get a copy of this message | ||
Note Submitter: shmohel at gmail dot com
----
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;
}
?>