note 84231 added to function.print-r
| From: | blasterjr at gmail dot com | Date: | Fri, 04 Jul 2008 11:54:30 +0000 |
| Subject: | note 84231 added to function.print-r | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-141162@lists.php.net to get a copy of this message | ||
i figured that I'd just submit a quick function, for those of you who have used the print_r
function, and wish you could take the data from there, exactly how its formatted, inside and out,
well here's the function for you, its made for plain text, but i figured it'd be nice,
I'm using it to store information about posts and gets, its recursive, so it supports
multidimensional arrays, along with full alignment almost exactly (if not exactly) like the print_r
function, took a bit to figure out, but it works like a charm
<?
function Array2String($array,$level=0)
{
$i = 0;
$j = 0;
$k = 0;
$l = 0;
while($i < $level)
{
$string .= ' ';
$i++;
}
$string = "Array \n";
if($level > 0)
{
$level++;
}
while($j < $level)
{
$string .= ' ';
$j++;
}
$string .= "(\n";
foreach($array as $key => $value)
{
while($k <= $level)
{
$string .= ' ';
$k++;
}
$k = 0;
if(is_array($value))
{
$newLevel = (int)$level+1;
$string .= "[".$key."] => ".Array2String($value,$level+1);
}
else
{
$string .= "[".$key."] => ".$value."\n";
}
}
while($l < $level)
{
$string .= ' ';
$l++;
}
$string .= ") \n";
if($level > 0)
{
$string .= "\n";
}
return $string;
}
?>
----
Server IP: 64.71.164.2
Probable Submitter: 74.211.4.208
----
Manual Page -- http://www.php.net/manual/en/function.print-r.php
Edit -- https://master.php.net/note/edit/84231
Del: integrated -- https://master.php.net/note/delete/84231/integrated
Del: useless -- https://master.php.net/note/delete/84231/useless
Del: bad code -- https://master.php.net/note/delete/84231/bad+code
Del: spam -- https://master.php.net/note/delete/84231/spam
Del: non-english -- https://master.php.net/note/delete/84231/non-english
Del: in docs -- https://master.php.net/note/delete/84231/in+docs
Del: other reasons-- https://master.php.net/note/delete/84231
Reject -- https://master.php.net/note/reject/84231
Search -- https://master.php.net/manage/user-notes.php