Re: How get the name of the array variable?
| From: | DL Neil | Date: | Fri, 15 Feb 2002 12:47:13 +0000 |
| Subject: | Re: How get the name of the array variable? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-84889@lists.php.net to get a copy of this message | ||
Tomek,
> I got the problem , I want make preety debug function that shows array keys
> and values and name of the variable containing array:
> Here it is:
>
> function show_arr($array)
> //wyswietla wartosci z tablicy wraz z kluczami (przeznaczone do debugowania)
> {
> if(DABUG)
> {
> echo "<b>-------------------------------------------</b><br>";
> echo "Array contents<b>".strval($array)."</b><br>";
> while(list($k,$v)=each($array))
> {
> echo "$k = $v<br>";
> }
> echo "<b>-------------------------------------------</b>";
> }
> }
>
> unfortunatly strval want work with arrays...
> Any possible solution how to get name of the array variable?
This doesn't solve the strval problem, but in my debug output I wasn't so interested in
the array's name, as in
the meaning/status of the data it contained. Here is an equivalent approach (- the idea of nesting
the two
functions was the subject of a conversation with Torben here, a few days back):
Function ShowList( $title, $aList )
// Debug output routine to echo an array/list to the screen
// requires a documentary name for the list as $title
// requires the array to be listed as $aList
// NB co-requisite FnShowListItem
{
echo "<br>Listing array=$title: n=" . count( $aList );
array_walk( $aList, "FnShowListItem" );
}
Function FnShowListItem( $item, $key ) { echo "<br>$key=" . $item . "~"; }
//end of function ShowList
In the main routine make a call something like:
if ( DEBUG ) ShowList( "Prefixed", $aURLs );
Please feel free to translate it into Polish.
I haven't tried to time/test, but I figured that the array_walk() would be more efficient than
writing an
(interpreted) PHP loop to run through the entire array/list, even with the function call.
Perhaps someone can confirm/refute that?
Regards,
=dn