tags:

views:

65

answers:

1

If I have an array named $myArray how can I get a reference to it from a string of the same name myArray. I tried:

eval('myArray');

But that gave me an error.

+6  A: 

Should be

${"myArray"}

or if the string is contained in another variable:

$a = "myArray";
$$a // <- points to $myArray

Read about variable variables.

Felix Kling
Very useful. But can be very confusing if used improperly. Thanks!
John Isaacks
Also I figured out...just to make your list complete in a class it is $this->$a
John Isaacks