I don't normally dish out free code, but this sounded like a challenge to me and here's what I came up with:
function show(&$test) {
if(!is_scalar($test)) {
echo 'ERROR: show() - variable type not supported';
return FALSE;
}
$original = $test;
$test .= uniqid('FINDME');
if(($name = array_search($test, $GLOBALS)) && ($name === NULL || $name === FALSE)) {
echo 'ERROR: show() - variable name could not be found';
return FALSE;
} else {
$test = $original;
return $name;
}
}
show() returns the name of the variable (assuming it could find it). Note that the variable must be a scalar value. For more information on what a scalar value is, look at [man]is_scalar/man. You can probably extend this function to include arrays (at least), but I didn't go that far.