php - foreach loop stopping on the first xml element -
i have following xml data
<items> <request> <isvalid>true</isvalid> <itemlookuprequest> <condition>all</condition> <idtype>isbn</idtype> <itemid>0071762345</itemid> <responsegroup>alternateversions</responsegroup> <searchindex>all</searchindex> <variationpage>all</variationpage> </itemlookuprequest> </request> <item> <asin>0071762345</asin> <alternateversions> <alternateversion> <asin>b0058o8v9u</asin> <title> likeable social media: how delight customers, create irresistible brand, , amazing on facebook (& other social networks) [paperback] dave kerpen dave kerpen </title> <binding>unknown binding</binding> </alternateversion> <alternateversion> <asin>b00511onpg</asin> <title> likeable social media: how delight customers, create irresistible brand, , amazing on facebook (& other social networks) </title> <binding>kindle edition</binding> </alternateversion> <alternateversion> <asin>0071813721</asin> <title> likeable social media: how delight customers, create irresistible brand, , amazing on facebook (& other social networks) </title> <binding>hardcover</binding> </alternateversion> </alternateversions> </item> <item> <asin>b00511onpg</asin> <alternateversions> <alternateversion> <asin>0071762345</asin> <title> likeable social media: how delight customers, create irresistible brand, , amazing on facebook (and other social networks) </title> <binding>paperback</binding> </alternateversion> <alternateversion> <asin>b0058o8v9u</asin> <title> likeable social media: how delight customers, create irresistible brand, , amazing on facebook (& other social networks) [paperback] dave kerpen dave kerpen </title> <binding>unknown binding</binding> </alternateversion> <alternateversion> <asin>0071813721</asin> <title> likeable social media: how delight customers, create irresistible brand, , amazing on facebook (& other social networks) </title> <binding>hardcover</binding> </alternateversion> </alternateversions> </item> </items> </itemlookupresponse>
and using code search each binding element , stuff this
foreach($xml->items->item->alternateversions->alternateversion->binding $bookbinding) { //loop through xml data find correct asin kindle edition foreach ($xml->items->item->alternateversions->alternateversion->asin $kindlestring) { var_dump ($bookbinding); if (preg_match('/kindle edition/i',$bookbinding)) { //do stuff } } }
but getting first iteration of $binding , $asin instead of 4 elements output var_dump "unknown binding" & b0058o8v9u
this might you
foreach($xml->items->item $item){ foreach($item->alternateversions->alternateversion $alt_version){ var_dump($alt_version->binding); var_dump($alt_version->asin); ... } }
first iterate throught 'item' , 'alternateversion'.
Comments
Post a Comment