For example, I know how to take an arbitrary set of keys and use them to make object references like this...
$arr = array("A", "B", "C");
foreach($arr as $key):
echo $obj->{$key} . "\n";
endforeach;
// prints $obj->A, $obj->B and $obj->C
But what if I have multiple levels of references within an object that I want to access? Is it possible to add more arrow operators on the fly?
$arr = array(array("A", "B"),
array("C", "D", "E"),
array("F"));
foreach($arr as $key_arr):
// ???
endforeach;
// prints $obj->A->B, $obj->C->D->E, $obj->F
You have to loop over the names and maintain a reference on the last object before to echo.
$ref = $obj
$ref = $ref->A
$ref = $ref->B
so$ref->A->B