Re: Variable name as a variable?
| From: | Tommy Pham | Date: | Mon, 05 Oct 2009 15:05:27 +0000 |
| Subject: | Re: Variable name as a variable? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-298601@lists.php.net to get a copy of this message | ||
----- Original Message ----
> From: Dotan Cohen <dotancohen@gmail.com>
> To: php-general. <php-general@lists.php.net>
> Sent: Mon, October 5, 2009 7:56:48 AM
> Subject: [PHP] Variable name as a variable?
>
> I need to store a variable name as a variable. Note quite a C-style
> pointer, but a way to access one variable who's name is stored in
> another variable.
>
> As part of a spam-control measure, a certain public-facing form will
> have dummy rotating text fields and a hidden field that will describe
> which text field should be considered, like this:
>
> input type="text" name="text_1"
> input type="text" name="text_2"
> input type="text" name="text_3"
> input type="hidden" name="real_field" value="text_2"
>
> As this will be a very general-purpose tool, a switch statement on the
> hidden field's value would not be appropriate here. Naturally, the
> situation will be much more complex and this is a non-obfuscated
> generalization of the HTML side of things which should describe the
> problem that I need to solve on the server side.
>
> Thanks in advance for any ideas.
>
> --
> Dotan Cohen
>
> http://what-is-what.com
> http://gibberish.co.il
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
You mean something like this?
$var_name = "text_2";
echo $$var_name; // equivalent to echo $text_2;
Regards,
Tommy