$var = "array";
$$var=array("1","2");
How can I call the array in $$var without using foreach? I want a method like $$var[0], but this doesn't work.
$var = "array";
$$var=array("1","2");
How can I call the array in $$var without using foreach? I want a method like $$var[0], but this doesn't work.
When you run this piece of code:
$var = "array";
$$var = array("1","2");
...it is identical to this:
$array = array("1","2");
So you can do this:
echo $array[0];
...or this:
echo ${$var}[0];
If you must use variable variables - and 99.99% of the time arrays are a better solution - you should always use braces for clarity and disambiguation.
See the variable variables reference for more information.