digitaldanuk Posted June 13, 2011 Share Posted June 13, 2011 hey all, im new here i seem to have taken leave of my senses this morning... and i am struggling to extract this array (SellerListing) from this simplexmlelement php object... $Obj = SimpleXMLElement Object ( [TotalResults] => 9160 [TotalPages] => 500 [sellerListing] => Array ( [0] => SimpleXMLElement Object ( [ExchangeId] => Y14M5526938M9611744 [ListingId] => 0309J054986 ) [1] => SimpleXMLElement Object ( [ExchangeId] => Y14M6408230M7657367 [ListingId] => 0309J777173 ) [2] => SimpleXMLElement Object ( [ExchangeId] => Y14M1914847M3622568 [ListingId] => 0604A723659 ) ) I have tried $Obj->SellerListing but that just gets the first in the array! What i would love to do is foreach($Obj->SellerListing as $Item) { // blah blah but all i seem to be able to do is get the first one from the array. It is definitely an array! *feels stupid* Quote Link to comment https://forums.phpfreaks.com/topic/239220-simplexmlelement-which-contains-an-array-how-to-get-it/ Share on other sites More sharing options...
salathe Posted June 13, 2011 Share Posted June 13, 2011 It is definitely an array! Sorry to break this to you but, it is not an array; the print_r() output lies. SimpleXMLElement objects are Traversable, so you can loop over them but they're not arrays. Given the output from print_r(), you should be able to use foreach($Obj->SellerListing as $Item) { // blah blah --- if that does not work, then please show the XML that you're working with (echo $Obj->saveXML();). P.S. Welcome to PHPFreaks. Quote Link to comment https://forums.phpfreaks.com/topic/239220-simplexmlelement-which-contains-an-array-how-to-get-it/#findComment-1229032 Share on other sites More sharing options...
digitaldanuk Posted June 13, 2011 Author Share Posted June 13, 2011 thank you I am indeed a numpty and i have now resolved this. I tried what you said and it was still not playing ball - turns out though it was another bit of code in the loop routine that was making me "think" there was nothing there but there was! Thank you for your help! Quote Link to comment https://forums.phpfreaks.com/topic/239220-simplexmlelement-which-contains-an-array-how-to-get-it/#findComment-1229049 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.