Simplexml object with dynamic path

97 views Asked by At

I would like to dynamically define attribute path for fetched attribute in simplexml object. I tried following, but it didn't work. Is this possible in PHP?

$xml = $z->readOuterXML();
$item = simplexml_load_string($xml);

// This works
echo $item->attribute1->attribute2->attribute3;

// However I want to dynamically define path for attribute like this, this example is not really working
$path = "attribute1->attribute2->attribute3";
echo $item->{$path};
0

There are 0 answers