Re: traverse a multidimensional array
| From: | Andreas Pour | Date: | Fri, 21 Jul 2000 09:45:43 +0000 |
| Subject: | Re: traverse a multidimensional array | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-7538@lists.php.net to get a copy of this message | ||
Lez Lytollis wrote:
>
> I came up the code below this morning - which I think does what I want
> (server didn't fall over anyway:)) - i.e recurses through through a deep
> structure and lists every element.
>
> function get_array_elems($arrResult){
function get_array_elems($arrResult, $where = "array")
> while(list($key,$value)=each($arrResult)){
> if (is_array($value)){
> get_array_elems($value);
get_array_elems($value, $where . "[$key]");
> }
> else {
> for ($i=0; $i<count($value);$i++){
> echo "array[$key]=$value<br>\n";
echo $where . "[$key]=" . $value[$i];
Untested, but should work better :-).
Ciao,
Andreas
> }
> }
> }
> }
>
> get_array_elems($arrResult);
>
> Thanks for the help
> Lez