I'm trying to use variable variables in a script, but I'm not finding them to work the way I'm expecting them. It seems like variable variables can't be used to call pre-defined values--it seems like you have to declare every variable variable value after instanciating the variable variable but can't use variable variables to reference previously defined vars (I hope this makes sense). Here's a little sample code to demonstrate what I'm talking about:
<?php
$foo_arr = array("one", "two", "three"); //define array
$a = "foo";
$b = "bar";
$c = $a . arr; // $$c should be $foo_arr
$d = $b . arr; // $$d is new var called $bar_arr
echo "${$c[0]}"; // like saying 'echo "${foo_arr[0]}", should output "one", right?
// unfortunately it outputs nothing.
$$d[0] = "Number 1"; //create new array element
echo "${$d[0]}"; // like saying 'echo "${bar_arr[0]}"
// outputs "Number 1".
?>
So the above script ONLY outputs the string "Number 1"--it doesn't seem to recognize that $$c[0] was a value set earlier as $foo_arr[0].
Is this how variable variables work, or is there something messed up in my syntax that is causing this script to not output what I'd expect it to output?
Thanks for any insight.