I'm trying to parse a string as a variable such as in the following. So if I have a string like "$"."foo" how do I parse that to return the value of the variable named $foo as in this instance?
<?php $foo = 9; $str = "myFoo=$"."foo"; parse_str($str); echo $myFoo; ?>
<?php $foo = 9; $str = "$myFoo=$"."foo"; eval($str); echo $myFoo; ?>
I tried that, it generates an error message when you run your code snippet.
Thanks for the try...
Corey,
I'm not quite sure of what you want to do but maybe this code will help.
<?php $foo = 9; $bar = 10;
$str = "foo"; echo ${$str}; // this will output 9
$str = "bar"; echo ${$str}; // this will output 10 ?>
Variable interpolation. How could I have missed that? Thanks much dude...
Corey