You are here: Re: $$foo « All PHP « IT news, forums, messages
Re: $$foo

Posted by -Lost on 08/22/06 21:03

"MS" <MS@nospam.com> wrote in message news:74ydnWjA75pX2XbZnZ2dnUVZ8tadnZ2d@bt.com...
>
> "Rik" <luiheidsgoeroe@hotmail.com> wrote in message
> news:a1581$44eb3244$8259c69c$28518@news2.tudelft.nl...
>> MS wrote:
>> > I saw on the news group a little while back somebody asking about
>> > $$foo type variables.
>> >
>> > I didn;t pay much attention then but I now have reason to use it.
>> >
>> > Can somebody point me to the page on php.net that discusses the use
>> > and how to build such variables.
>> >
>> > $varname = "test";
>> >
>> > $$varname == $test // is this true?
>>
>> Indeed.
>>
>> > Can you create something like
>> > $sel_$varname
>> > to create a variable called
>> > $sel_test
>>
>>
>> Hmmz, I think that will work.You can solve ambuguity problems by {}.
>> So $sel_{$varname}_foo == $sel_test_foo
>>
>
> Think I have cracked it...
>
> $varname = "test";
>
> $sel{$varname} = "the second value";
>
> // $seltest does not contain "the second value".. but
> // $sel{test} does.

Bear in mind this is most likely useless (as in improper code), but you can use:

print $sel{test};

However, you will most likely get an undefined constant warning (which is what it is).
You can halt the message and still get your date by doing:

print @$sel{test};

Hehe... in my example I did:

$variable = 'rick';
$name_{$variable} = 'james';

print @$name_{rick};
print $name_{$variable};

Both of which give us "james, bitch". Sorry, just "james".

-Lost

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация