On Tue, 23 Sep 2003 21:41:46 GMT, "Randell D."
<yo**************************@yahoo.com> wrote:
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 multidimensional 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($_SERVER) it would dump
out the contents of the array $_SERVER. How could I have my output titled
(for example) "Contents of _SERVER array"...
In short; you can't. In your example it's passed by value, and even if it were
passed by reference, it doesn't matter; since the 'variable name' is always
$arrayName. Variable names don't get passed around; only the data they
represent does.
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...
The contents of multidimensional arrays will have the keys to print as the
'name', so that's not a problem, but you're not going to be able to get hold of
the top-level variable name with the way you're calling it.
You _could_ pass a variable name, not the variable itself, but that would only
work with global variables. Any local variables would be out of scope within
the function call, so you wouldn't see them.
If PHP had macros, you could define one that changed dumpArray(x) into
dumpArray($x, 'x') - but unless they've sneaked macros in since I last looked,
you can't. So redefining your function take a name would be about the only way.
--
Andy Hassall (an**@andyh.co.uk) icq(5747695) (
http://www.andyh.co.uk)
Space: disk usage analysis tool (
http://www.andyhsoftware.co.uk/space)