So I've followed a few questions on here to try and get this to work....but I just can't seem to crack it. Essentially what i'm trying to do is loop through an XML file and return key => value pairs for elements from that file. For a bit more context, I'm trying to store an item's ASIN (Amazon API) as the key and it's image URL as the value in an array.
Here's the structure of the XML file, in case these helps someone determine where my code is flawed:
<Items>
<Request>
<IsValid>True</IsValid>
<ItemSearchRequest>
<Keywords>biology</Keywords>
<ResponseGroup>Images</ResponseGroup>
<SearchIndex>Books</SearchIndex>
</ItemSearchRequest>
</Request>
<TotalResults>280951</TotalResults>
<TotalPages>28096</TotalPages>
<MoreSearchResultsUrl>
http://www.amazon.com/gp/redirect.html?camp=2025&creative=386001&location=http%3A%2F%2Fwww.amazon.com%2Fgp%2Fsearch%3Fkeywords%3Dbiology%26url%3Dsearch-alias%253Dstripbooks&linkCode=xm2&tag=comparcom035-20&SubscriptionId=AKIAIQ7UEDX4CFRSBDXA
</MoreSearchResultsUrl>
<Item>
<ASIN>0321558235</ASIN>
<SmallImage>
<URL>
http://ecx.images-amazon.com/images/I/41UWC4kbxGL._SL75_.jpg
</URL>
<Height Units="pixels">75</Height>
<Width Units="pixels">62</Width>
</SmallImage>
and here's the code I'm working with:
$xml = simplexml_load_file($SignedRequest);
$image = simplexml_load_file($getimage);
foreach ($image->Items->Item->ASIN as $key => $value) {
$array[$key] = $image->Items->Item->SmallImage->URL;
}
print_r($array);
My output looks like this:
Array ( [ASIN] => SimpleXMLElement Object ( [0] => http://ecx.images-amazon.com/images/I/41UWC4kbxGL._SL75_.jpg ) )
I think I'm close.....but can anyone point out what I'm doing wrong here? I can't seem to get my loop to assign the key and value properly without throwing some kind of error.