Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Variable in variable.

0 views
Skip to first unread message

João Cândido de Souza Neto

unread,
Aug 26, 2010, 9:54:49 AM8/26/10
to php-g...@lists.php.net
I know that in PHP I can use this:

$var1 = "text";
$var2 = '$var1';
4cho $$var2;

So it gives me "text".

My question is, is there a way of doing it with constant like this?

define("CONST", "text");
$test = "CONST";
echo $$test;

So it gives me "text".

Thanks in advance.
--
João Cândido de Souza Neto


Robert Cummings

unread,
Aug 26, 2010, 10:03:38 AM8/26/10
to João Cândido de Souza Neto, php-g...@lists.php.net
On 10-08-26 09:54 AM, João Cândido de Souza Neto wrote:
> I know that in PHP I can use this:
>
> $var1 = "text";
> $var2 = '$var1';
> 4cho $$var2;
>
> So it gives me "text".

It would if you didn't have typos and the wrong quotes in the above :)

> My question is, is there a way of doing it with constant like this?
>
> define("CONST", "text");
> $test = "CONST";
> echo $$test;
>
> So it gives me "text".

http://ca3.php.net/manual/en/function.constant.php

Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

João Cândido de Souza Neto

unread,
Aug 26, 2010, 10:06:58 AM8/26/10
to php-g...@lists.php.net
Really cool...

Thanks and fogive me by my mistake. hehe

--

João Cândido de Souza Neto

"Robert Cummings" <rob...@interjinn.com> escreveu na mensagem
news:4C76743A...@interjinn.com...

0 new messages