$test = "Hello World!";
function showvar($var) {
foreach($GLOBALS as $key => $value) {
if($value == $var) {
$varname = $key;
}
}
echo "Variable Name: ".$varname."<br>\n";
echo "Variable Value: ".$var."<br>\n";
}
showvar($test);
This is the only thing that works for me.....I know it is messy
-----Original Message-----
From: Michael Sims [mailto:[EMAIL PROTECTED]
Sent: 05 May 2004 4:23 PM
To: [EMAIL PROTECTED]
Subject: RE: [PHP] Print a variable's name
Ahbaid Gaffoor wrote:
> Thanks Ryan,
>
> but what I want is to be able to pass any variable to a procedure and
> have the variable name and value printed by the procedure.
>
> Can this be done?
>
> I'm trying to extend my library of debugging functions/procedures by
> having a procedure which can be used to "inspect" a variable whenever
> I call it.
This is a bit kludgy, but should work:
function showvar($varname) {
if (!isset($GLOBALS[$varname])) { return; }
echo "Now showing: $varname\n";
echo "Value: ".$GLOBALS[$varname]."\n";
}
$s1 = "Hello World";
showvar('s1');
HTH
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php