I have a script (below) that can be passed an array and it will dump the
contents of the array in to an html table - I use it during development so
its nothing sexy. It handles multidimsional arrays so any element that
itself is an array will also be broken down and displayed...
Thus... in order to keep track of tables in a multidimensiona l array, I'm
trying to print the name of each array before its displayed... Does anybody
know a method how I could do this?
Example: If I were to call the script with dumpArray($_SER VER) it would dump
out the contents of the array $_SERVER. How could I have my output titled
(for example) "Contents of _SERVER array"... since I can pass it many
different arrays, it needs to be dynamic and not hard coded... I could be
passing it any array with any name, and multi-dimensional arrays could
contain other arrays...
All help appreciated - script follows below...
function dumpArray($arra yName)
{
// Dump an array to the client in an html table format
// Useful for debugging
print("<BR><TAB LE BORDER=1>");
if(is_array($ar rayName))
{ $telements=coun t($arrayName);
print("<th align=right>#</th><th>$telemen ts Elements</th><th
align=right>str len</th><tr>");
foreach($arrayN ame as $key=>$value)
{ if(is_array($va lue))
{ print("<TD COLSPAN=3>Eleme nt $key</TD><TR>");
dumpArray($valu e); }
else
{ $length=strlen( $value);
if($length==0)
{ $value=" " ; }
else
{ $value=htmlenti ties($value); }
print("<TH>$key </TH><TD>$value</TD><td>$length</td><TR>");
}
}
}
else
{ print("<TH>Arra y Not Defined or Empty - Cannot Dump</TH><TR>"); }
print("</TABLE>");
return;
}
--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet?
Comment