Re: find out names of keys in an array

From: Date: Tue, 11 Sep 2001 01:24:30 +0000
Subject: Re: find out names of keys in an array
Groups: php.general 
Request: Send a blank email to php-general+get-66837@lists.php.net to get a copy of this message
Below is a function I found in the manual or somewhere on php.net. I tried to find it to provide a link so the author would get some credit. Sorry but no luck. Anyway, this is a handy little function when you are trying to figure out the contents of an array. -kevin function array_tree($array , $prep='') { if(!is_array($array)) { print '<b>array_tree:</b> This is not an array'; return false; } $prep .= '|'; while(list($key, $val) = each($array)) { $type = gettype($val); if(is_array($val)) { $line = "-+ $key ($type)\n"; $line .= array_tree($val, "$prep "); } else { $line = "-> $key = \"$val\" ($type)\n"; } $ret .= $prep.$line; } return $ret; } function parray_tree($array) { print '<pre>'; print array_tree($array); print '</pre>'; return true; }

« previous php.general (#66837) next »