Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_php thread: RE: Looping TWO dimension array


Message #1 by "jorge" <jorge@d...> on Tue, 29 Oct 2002 22:52:18 -0600
On the topic of var_dump() etc....

This is the function I wind up using at some point in ever PHP script I 
develop. It doesn't print -- sometimes I e-mail the debug info to myself 
-- but it does provide a ton of info. I often use it in conjuction with 
a debug array (e.g., $gaDEBUG) to build a list of comments during an 
execution and then dump them at the end.

I haven't looked at print_r() and var_dump() -- I'll have to compare 
this to them.



function PE_DEBUG_ArrayAsHTMLList( $va) // string
/*
	Given an array, this encodes it as an HTML unordered list, which
	each node in the form "key:value". It's recursive, so nested arrays
	may be represented. The top-level tags, <UL></UL>, are included.
*/
{
	/*
		Variables
	*/
	$return =3D "<UL>\n";
=09
	// if arg isn't an array return message and EXIT
	if ( ! is_array($va) ) return '<P><B>Not an array.</B></P>';
=09
	foreach ( $va as $key=3D>$val )
	{
		if ( is_array( $val ) )
		// create a sub-tree
		{
			$return .=3D "\n<LI>$key (Array of " . count($val) . ")</LI>\n";
			$return .=3D PE_DEBUG_ArrayAsHTMLList( $val );
		}
		else
		{
			$return .=3D "<LI>$key:$val (" . gettype($val) . ")</LI>\n";
		}
	}
=09
	$return .=3D "</UL>\n";
	return $return;
}



dsb

***************************************       
David Scott-Bigsby
Product Manager, Web Site and PEDN

PureEdge Solutions
The Leader in Secure XML e-Forms

v:250-708-8145  f:250-708-8010
1-888-517-2675   www.PureEdge.com
***************************************

  Return to Index