This works with simple variables. But it shows empty result with complex variables. AM I MISSING SOMETHING HERE? or is there anyother way around. Thanks.
#1. This works with simple variables.
$object = "fruit";
$fruit = "banana";
echo $$object; // <------------ WORKS :outputs "banana".
echo "\n";
echo ${"fruit"}; // <------------ This outputs "banana".
#2. With complex structure it doesn't. am I missing something here?
echo "\n";
$result = array("node"=> (object)array("id"=>10, "home"=>"earth", ), "count"=>10, "and_so_on"=>true, );
#var_dump($result);
$path = "result['node']->id";
echo "\n";
echo $$path; // <---------- This outputs to blank. Should output "10".
result['node']->id, of course that variable does not exist (not wanting to say it's invalid), hence echoing empty.eval()function can do. However it's still not what you want. I don't think you can achieve such a dynamic parsing (and also I'm not sure why you want to do something like that). If we can parse that string to evaluate the expression to some assignable result, it would make theeval()become redundant (or less powerful).