
Untitled
By: a guest on
Apr 25th, 2012 | syntax:
None | size: 2.24 KB | hits: 11 | expires: Never
How to loop through a SimpleXMLElement object in Php?
SimpleXMLElement Object
(
[products] => SimpleXMLElement Object
(
[product] => Array
(
[0] => SimpleXMLElement Object
(
[product_name] => PROD1
[price] => 100.2
[has_special_price] => true
[special_price_desc] => DESC SPECIAL PRICE
[id_product_remote] => CUSTOMID-01
[decimals] => 0
[category_key] => 1
[packaging_key] => 2
[stock_type_key] => 1
)
[1] => SimpleXMLElement Object
(
[product_name] => PROD2
[price] => 200.2
[has_special_price] => false
[special_price_desc] => DEsdSC SPECIAL PRICE
[id_product_remote] => CUSTOMID-02
[decimals] => 0
[category_key] => 1
[packaging_key] => 2
[stock_type_key] => 1
)
)
)
[products_client] => SimpleXMLElement Object
(
[product_client] => Array
(
[0] => SimpleXMLElement Object
(
[id_client_remote] => CUSTOMCLIENT-01
[id_product_remote] => CUSTOMID-01
[custom_price] => 0
)
[1] => SimpleXMLElement Object
(
[id_client_remote] => CUSTOMCLIENT-02
[id_product_remote] => CUSTOMID-02
[custom_price] => 1
)
)
)
)
foreach($xml_object->products->product as $key => $product){
echo $product->product_name;
}
foreach($yourVar->products->product as $key => $val) {
echo $val->product_name; /// and so on
}