Re: Need an array parser(CONT)
| From: | Ernest E Vogelsinger | Date: | Wed, 28 Feb 2001 18:34:05 +0000 |
| Subject: | Re: Need an array parser(CONT) | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-42059@lists.php.net to get a copy of this message | ||
At 21:33 28.02.2001, Dallas K. said:
--------------------[snip]--------------------
>I am looking for somthing that will parse a multidimentional array of any
>size, and return a key / value listing for debugging....
>
>Example:
>
>if I have an array such as...
>
>$arr[name] = dallas
>$arr[address][city] = austin
>$arr[address][state] = Texas
>$arr[somthing][somthing_else][blah1]= some_value1
>$arr[somthing][somthing_else][blah2]= some_value2
>$arr[somthing][somthing_else][blah3]= some_value3
>
>I would want the result to be displaied as:
>
>ARR
> name --- dallas
> address --- city --- austin
> address --- state --- Texas
> somthing --- somthing_else --- blah1 --- some_value1
> somthing --- somthing_else --- blah1 --- some_value1
--------------------[snip]--------------------
Not tested, but try this as an example:
<?php
function showArray($name, $value)
{
if (is_array($value)) {
if (strlen($name)) $name .= " --- ";
while (list($key, $data) = each ($value))
$result .= showArray($name . $key, $data);
}
else
$result = "$name --- $value\n";
return $result;
}
$a = array("name" => "dallas",
"address" => array("city" => "austin",
"state" => "Texas"),
"something" => array("something else" =>
array("blah1",
"some_value1",
"blah2",
"some_value2")));
print(showArray(null, $a);
?>
this should recursively go into multi-dimensional arrays and construct an
output similar to your requirements.
...ebird
>O Ernest E. Vogelsinger
(\) http://www.1-at-web.at/
^ ICQ# 13394035