|
Posted by Daniel Kempkens on 06/15/07 19:53
Ciaran schrieb:
> On Jun 15, 8:39 pm, Moot <use...@mootsoft.com> wrote:
>> On Jun 15, 3:19 pm, Ciaran <cronok...@hotmail.com> wrote:
>>
>>> Can someone please give me a hand with this?
>>> $arr=array(2,4,5,6);
>>> $test='arr';
>>> echo (eval("$".$test."[0]"));
>>> I'm trying to get it to echo 2
>>> Thanks a lot,
>>> Ciarán
>> Try this:
>> eval("echo $".$test."[0];");
>>
>> Don't treat eval like a function that returns a string, make sure the
>> entire PHP statement is passed to it (including the ;).
>>
>> An alternative, that looks like what you were trying to accomplish,
>> but without the eval would be:
>> echo ${$test}[0];
>
>
> Oh great thanks , that works well. I'm used to the eval function in
> flash actionscript and I just thought the php one would be the same.
> What if I wanted to duplicate the original array?
>
> $arr2=${$test};
>
> ??
> Cheers
Works exactly the way you guessed ;)
[Back to original message]
|