|
Posted by Ciaran on 06/15/07 20:04
On Jun 15, 8:53 pm, Daniel Kempkens <Daniel.Kempk...@gmail.com> wrote:
> 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 ;)- Hide quoted text -
>
> - Show quoted text -
Great! That seems to be the functionality I was looking for with eval.
Thanks for the help guys!
[Back to original message]
|