Re: Easier way to get the name of a variable?
| From: | David Tulloh | Date: | Tue, 15 Aug 2006 22:41:11 +0000 |
| Subject: | Re: Easier way to get the name of a variable? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-240738@lists.php.net to get a copy of this message | ||
Chris W. Parker wrote:
> Hello,
>
> After some "intense" searching of Google I found one example at
> http://us2.php.net/language.variables on how to get the name of
> a
> variable. But it looks pretty expensive.
>
> <snip>
>
> Anyone aware of a simple language construct(?) that can do this? I'm on
> PHP 4.3.9.
>
get_defined_vars() can get you a list of all the currently defined
variables. If you have the value of the variable, you can use
array_search() to find the (first) key.
I do have some misgivings about what you are trying to do though. I
can't see a case where this would be the best way to solve a problem.
David