Re: Name of variable to string

From: Date: Fri, 08 Feb 2008 15:31:28 +0000
Subject: Re: Name of variable to string
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-268945@lists.php.net to get a copy of this message
On Feb 8, 2008 10:25 AM, Jason Pruim <japruim@raoset.com> wrote: > > On Feb 8, 2008, at 10:14 AM, tedd wrote: > > > Hi gang: > > > > From a variable with the name of $this_variable -- how do I get a > > string 'this_variable' ? > > > Hey tedd, > > What is the end result you want? for debugging and checking variable > contents, I've simply: echo "this_variable = $this_variable"; > > But that was just for debugging, in a large environment, it could be > quite tedious to type all that out... What Tedd means is this: ;-P <? function vname(&$var,$scope=false,$prefix='unique',$suffix='value') { if($scope) { $vals = $scope; } else { $vals = $GLOBALS; } $old = $var; $var = $new = $prefix.rand().$suffix; $vname = FALSE; foreach($vals as $p => $v) { if($v === $new) { $vname = $p; } } $var = $old; return $vname; } ?> -- </Dan> Daniel P. Brown Senior Unix Geek <? while(1) { $me = $mind--; sleep(86400); } ?>

« previous php.general (#268945) next »