RE: [PHP] Print a variable's name

From: Date: Wed, 05 May 2004 15:48:53 +0000
Subject: RE: [PHP] Print a variable's name
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-185443@lists.php.net to get a copy of this message
Dave Avent wrote: > function showvar($var) { > > foreach($GLOBALS as $key => $value) { > if($value == $var) { > $varname = $key; > } > } The problem with the above is that it assumes that there will never be more than one global variable that contains the same value, and will give incorrect output in this case: $s1 = "Hello World"; ... $s2 = "Hello World"; ... showvar($s1); Also it's probably a better idea to have the "showvar" function use print_r() or var_export() in case it is passed something other than a scalar.

« previous php.general (#185443) next »