Re: Need key() equivalent for string variable

From: Date: Tue, 23 Jan 2001 03:40:56 +0000
Subject: Re: Need key() equivalent for string variable
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-36136@lists.php.net to get a copy of this message
In article <069f01c084ca$1642a320$64aa8ed8@142.170.100>, richard@zend.com ("Richard Lynch") wrote: > > I'm trying to pass a string variable to a custom function, echoing its > > *value on one line, and its *name (that is, its key if this were an array > > I think you are looking for "variable variables"... A variable variable results in a second variable which is named for the *value of the first. So what I need is a sort of "inverse variable variable" to extract the *name of the first variable: $foo="bar" echo $foo //"bar" echo [something] //"foo" I ended up doing a clumsy workaround by altering $foo-- $foo="bar" $foo=array("foo"=>$foo) echo $foo[key($foo)]; //"bar" echo key($foo); //"foo" --but then I'm having to tell PHP the very info that I was hoping it'd dynamically tell me. Any other suggestions would be much appreciated! -- CC

« previous php.general (#36136) next »