unable to assign a SimpleXmlelementObject to a variable [duplicate]




This question already has an answer here:




I have an array I create off API return. The return looks like this:



SimpleXMLElement Object
(
[Items] => SimpleXMLElement Object
(
[Item] => SimpleXMLElement Object
(
[ItemId] => 9780136035480
[DetailURLPage] => http://ift.tt/1te6G96
[AddToCartButton] => http://ift.tt/1rCXLRR
[ItemAttributes] => SimpleXMLElement Object
(
[Title] => Nursing Basics for Clinical Practice [With Access Code]
[ISBN10] => 0136035485
[ISBN13] => 9780136035480
)

[OfferSummary] => SimpleXMLElement Object
(
[LowestNewPrice] => $0.00
[LowestUsedPrice] => $11.48
[TotalNew] => 0
[TotalUsed] => 1
)

)

)

)


I create an array of variables from the object as below:



$itemID = $xml->Items->Item->ItemId;
$title = $xml->Items->Item->ItemAttributes->Title;
$isbn10 = $xml->Items->Item->ItemAttributes->ISBN10;
$isbn13 = $xml->Items->Item->ItemAttributes->ISBN13;
$buyurl= $xml->Items->Item->AddToCartButton;


Not sure why, but everything outputs great except for the $buyurl. When I use print_r on the array with the variables, I get this output:



Array
(
[0] => Array
(
[channel] => blah.com
[buyurl] => SimpleXMLElement Object
(
[0] => http://ift.tt/1rCXLRW
)

[price] => 11.48
[condition] => used
[shipping] => 0
)

)


For some reason, I cannot seem to get rid of the buyurl object and simply get the buyurl into a regular key -> value relationship. Any ideas are sure appreciated!


No comments:

Post a Comment