note 12766 deleted from ref.var by felipe

[email protected]
Newsgroups php.notes
Message-ID <[email protected]>
Note Submitter: tapken at engter dot de 

----

This function will return a nice tree-view of an array. It's like var_dump but much prettier :-) 
Very useful to analyze an array while debugging. 
function parray($array,$prep = '') { 
/* (c) by Roland Tapken <[email protected]> */ 
$prep = "$prep|"; 
while(list($key,$val) = each($array)) { 
$type = gettype($val); 
if(is_array($val)) { 
$line = "-+ $key ($type)\n"; 
$line .= parray($val,"$prep "); 
} else { 
$line = "-&gt; $key = \"$val\" ($type)\n"; 
} 
$ret .= $prep.$line; 
} 
return $ret; 
} 

Example:
$array = array("test",2,array("foo" => "bar"), 4.23); 
echo "<pre>"; 
echo parray($array); 
echo "</pre>"; 
This will print: 
|-> 0 = "test" (string) 
|-> 1 = "2" (integer) 
|-+ 2 (array) 
| |-> foo = "bar" (string) 
|-> 3 = "4.23" (double)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.