I have a sample object array as a variable $xmlobj
SimpleXMLElement Object(
[SearchId] => 10769920113727_1556288871357_170040
[Categories] => SimpleXMLElement Object
(
[@attributes] => Array
(
[total_subcategories] => 1
)
[SubCategory] => SimpleXMLElement Object
(
[Title] => Reproductor MP3 y Multimedia
[Value] => 122701
[NumberOfProducts] => 1
)
)
[Products] => SimpleXMLElement Object
(
[@attributes] => Array
(
[totalResultsAvailable] => 1
[firstResultPosition] => 1
[totalResultsReturned] => 1
[currency] => EUR
[totalMerchantsAvailable] => 1
[searchOperator] => and
)
[Product] => SimpleXMLElement Object
(
[Offer] => SimpleXMLElement Object
(
[@attributes] => Array
(
[id] => f94af9ec5186b53051c9ccf083ebddec
[type] => MANUFACTURER_PRODUCTS
)
[Title] => Apple iPod Nano 6 8 GB Gris
[Description] => iPod Nano 6 8 GB - Gris
[LastModified] => 2019-04-26 01:10:56
[MobileFriendly] => false
[Merchant] => SimpleXMLElement Object
(
[@attributes] => Array
(
[id] => 15348713
)
[Name] => Backmarket
)
[Price] => SimpleXMLElement Object
(
[@attributes] => Array
(
[currency] => EUR
)
[Price] => 99.99
[DeliveryCost] => 19.9
[DeliveryCostDetails] => SimpleXMLElement Object
(
[DeliveryCost] => 19.9
)
[TotalPrice] => 119.89
[PriceWithoutRebate] => 190
[Rebate] => 47
)
[ProductClass] => 2
[Availability] => 1
[DeliveryTime] => 24H / 4 días laborables
[Promo] => SimpleXMLElement Object
(
)
[OffensiveContent] => false
[FinancingOption] => SimpleXMLElement Object
(
)
[MerchantCategory] => Alta Tecnología Imágenes y sonidos Reproductor de MP3 Y MP4
[Brand] => Apple
[BrandId] => 211
[GreenProduct] => false
)
)
)
Now when I want to access e.g. price i do it like this:
$product_total_price = $xmlobj->Products->Product->Offer->Price->TotalPrice;
And it's OK - I get what I want, but I am having issue when I want "dynamically" to change what I am looking for like:
$search_part = "Products->Product->Offer->Price->TotalPrice";
$product_total_price = $xmlobj->$search_part;
I obviously get nothing... even when I try:
$product_total_price = $xmlobj."->".$search_part;
So my question is... how to do it ? :)
Thanks !
"Products->Product->Offer->Price->TotalPrice"anyway. Maybe give more about how/why you want to do this.