|
Posted by Ciaran on 06/15/07 19:49
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
Navigation:
[Reply to this message]
|