• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 354
  • Last Modified:

Looping through an Array from Nusoap

A sort of followup question from the one here
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_24095118.html

I have been using some web services where until now I have been able to use simplexml_load_string and then
 something like foreach ($offerresult->offer as $offer) to loop through the results, however with this call I am getting "Warning: simplexml_load_string() expects parameter 1 to be string, array given". This was similar to the problem I had before which I solved by using the solution in the linked question above. However this appears to only be of use for one result returned, the results I am getting now have a few results all contained in [result] (returned code is below) that I want to loop though, can anyone suggest anything?
Array
(
    [runQuickReturn] => Array
        (
            [resultsAsXml] => <?xml version="1.0" encoding="UTF-8"?><root><result><ADDRESS1>97 Stoke Newington Church Street</ADDRESS1><ADDRESS2></ADDRESS2><ADDRESS3></ADDRESS3><AVGPRICE>&#xa3;24</AVGPRICE><BOOKINGS>1</BOOKINGS><CITY>London</CITY><COUNTRY>United Kingdom</COUNTRY><COUNTY></COUNTY><COVERS>2</COVERS><CUISINE>Mediterranean </CUISINE><ID>3752</ID><LARGEIMAGE>1</LARGEIMAGE><LARGEIMAGEBAR>0</LARGEIMAGEBAR><LAT>51.561900</LAT><LOCATION></LOCATION><LONG>-0.079500</LONG><MEDIUMIMAGE>1</MEDIUMIMAGE><MEDIUMIMAGEBAR>0</MEDIUMIMAGEBAR><NAME>Clicia</NAME><NUMOFFERS></NUMOFFERS><ORDERNAME>clicia</ORDERNAME><POSTCODE>N16 0UD</POSTCODE><SCORE>score</SCORE><SMALLIMAGE>1</SMALLIMAGE><SMALLIMAGEBAR>0</SMALLIMAGEBAR><TXTREVIEW>By day, Clicia is a good value neighbourhood caf&#xe9;; by night, a popular restaurant liked for its down-to-earth cosiness. Pretty lamps cast their multicoloured over an assortment of old mirrors and wall hangings. A simple Mediterranean menu of grills, fish, cassoulets, meze and vegetarian dishes...</TXTREVIEW></result><result><ADDRESS1>5 Chapel Market</ADDRESS1><ADDRESS2></ADDRESS2><ADDRESS3></ADDRESS3><AVGPRICE>&#xa3;24 and under</AVGPRICE><BOOKINGS>1</BOOKINGS><CITY>Islington</CITY><COUNTRY>United Kingdom</COUNTRY><COUNTY></COUNTY><COVERS>4</COVERS><CUISINE>Indian</CUISINE><ID>3902</ID><LARGEIMAGE>1</LARGEIMAGE><LARGEIMAGEBAR>0</LARGEIMAGEBAR><LAT>51.533500</LAT><LOCATION></LOCATION><LONG>-0.110000</LONG><MEDIUMIMAGE>1</MEDIUMIMAGE><MEDIUMIMAGEBAR>0</MEDIUMIMAGEBAR><NAME>Angel Curry Centre</NAME><NUMOFFERS></NUMOFFERS><ORDERNAME>angelcurrycentre</ORDERNAME><POSTCODE>N1 9EZ</POSTCODE><SCORE>score</SCORE><SMALLIMAGE>1</SMALLIMAGE><SMALLIMAGEBAR>0</SMALLIMAGEBAR><TXTREVIEW>&lt;b&gt;toptable Dining Awards 2009 - Runner Up: Best Value &amp; Best for Dining with friends &lt;/b&gt;&lt;BR&gt;&lt;BR&gt;Despite the name, Angel Curry Centre is actually a small and perfectly elegant modern Indian. Neither short on competition nor regulars, its success is right where it should be  in the consistency of...</TXTREVIEW></result><result><ADDRESS1>58 Stoke Newington Church Street</ADDRESS1><ADDRESS2></ADDRESS2><ADDRESS3></ADDRESS3><AVGPRICE>&#xa3;24 and under</AVGPRICE><BOOKINGS>0</BOOKINGS><CITY>London</CITY><COUNTRY>United Kingdom</COUNTRY><COUNTY></COUNTY><COVERS>0</COVERS><CUISINE>Thai</CUISINE><ID>4196</ID><LARGEIMAGE>1</LARGEIMAGE><LARGEIMAGEBAR>0</LARGEIMAGEBAR><LAT>51.562320</LAT><LOCATION></LOCATION><LONG>-0.076140</LONG><MEDIUMIMAGE>1</MEDIUMIMAGE><MEDIUMIMAGEBAR>0</MEDIUMIMAGEBAR><NAME>Lemongrass</NAME><NUMOFFERS></NUMOFFERS><ORDERNAME>lemongrass</ORDERNAME><POSTCODE>N16 0NB</POSTCODE><SCORE>score</SCORE><SMALLIMAGE>1</SMALLIMAGE><SMALLIMAGEBAR>0</SMALLIMAGEBAR><TXTREVIEW>Lemongrass restaurant in Stoke Newingtons most vibrant street is a stylish, upmarket purveyor of Thai cuisine both traditional and modern. The urban chic d&#xe9;cor is a soothing blend of natural wood with azure blue and creamy yellow. Theres sleek modern seating and lighting and a very cool chrome...</TXTREVIEW></result><result><ADDRESS1>392 Green Lanes</ADDRESS1><ADDRESS2></ADDRESS2><ADDRESS3></ADDRESS3><AVGPRICE>&#xa3;25 - &#xa3;34</AVGPRICE><BOOKINGS>0</BOOKINGS><CITY>London</CITY><COUNTRY>United Kingdom</COUNTRY><COUNTY></COUNTY><COVERS>0</COVERS><CUISINE>Indian</CUISINE><ID>4552</ID><LARGEIMAGE>1</LARGEIMAGE><LARGEIMAGEBAR>0</LARGEIMAGEBAR><LAT>51.621260</LAT><LOCATION></LOCATION><LONG>-0.105610</LONG><MEDIUMIMAGE>1</MEDIUMIMAGE><MEDIUMIMAGEBAR>0</MEDIUMIMAGEBAR><NAME>Shamiana Indian Restaurant</NAME><NUMOFFERS></NUMOFFERS><ORDERNAME>shamianaindianrestaurant</ORDERNAME><POSTCODE>N13 5PD</POSTCODE><SCORE>score</SCORE><SMALLIMAGE>1</SMALLIMAGE><SMALLIMAGEBAR>0</SMALLIMAGEBAR><TXTREVIEW>Theres nothing quite like discovering a great Indian in your neighbourhood, and residents of Palmers Green have certainly got the lock on that. Shamiana Indian Restaurant is a comfortable, locally-loved establishment, serving both old standards and new interpretations of classic regional Indian...</TXTREVIEW></result></root>
 
            [totalResultsAvailable] => 4.0
        )
 
)

Open in new window

0
Bateman
Asked:
Bateman
  • 2
1 Solution
 
Ray PaseurCommented:
Slightly reformatted for readability...
Array
(
    [runQuickReturn] => Array
        (
            [resultsAsXml] => 
            <?xml version="1.0" encoding="UTF-8"?>
            <root>
            
            <result>
            <ADDRESS1>97 Stoke Newington Church Street</ADDRESS1>
            <ADDRESS2></ADDRESS2>
            <ADDRESS3></ADDRESS3>
            <AVGPRICE>&#xa3;24</AVGPRICE>
            <BOOKINGS>1</BOOKINGS>
            <CITY>London</CITY>
            <COUNTRY>United Kingdom</COUNTRY>
            <COUNTY></COUNTY>
            <COVERS>2</COVERS>
            <CUISINE>Mediterranean </CUISINE>
            <ID>3752</ID>
            <LARGEIMAGE>1</LARGEIMAGE>
            <LARGEIMAGEBAR>0</LARGEIMAGEBAR>
            <LAT>51.561900</LAT>
            <LOCATION></LOCATION>
            <LONG>-0.079500</LONG>
            <MEDIUMIMAGE>1</MEDIUMIMAGE>
            <MEDIUMIMAGEBAR>0</MEDIUMIMAGEBAR>
            <NAME>Clicia</NAME>
            <NUMOFFERS></NUMOFFERS>
            <ORDERNAME>clicia</ORDERNAME>
            <POSTCODE>N16 0UD</POSTCODE>
            <SCORE>score</SCORE>
            <SMALLIMAGE>1</SMALLIMAGE>
            <SMALLIMAGEBAR>0</SMALLIMAGEBAR>
            <TXTREVIEW>By day, Clicia is a good value neighbourhood caf&#xe9;; by night, a popular restaurant liked for its down-to-earth cosiness. Pretty lamps cast their multicoloured over an assortment of old mirrors and wall hangings. A simple Mediterranean menu of grills, fish, cassoulets, meze and vegetarian dishes...</TXTREVIEW>
            </result>
            
            <result>
            <ADDRESS1>5 Chapel Market</ADDRESS1>
            <ADDRESS2></ADDRESS2>
            <ADDRESS3></ADDRESS3>
            <AVGPRICE>&#xa3;24 and under</AVGPRICE>
            <BOOKINGS>1</BOOKINGS>
            <CITY>Islington</CITY>
            <COUNTRY>United Kingdom</COUNTRY>
            <COUNTY></COUNTY>
            <COVERS>4</COVERS>
            <CUISINE>Indian</CUISINE>
            <ID>3902</ID>
            <LARGEIMAGE>1</LARGEIMAGE>
            <LARGEIMAGEBAR>0</LARGEIMAGEBAR>
            <LAT>51.533500</LAT>
            <LOCATION></LOCATION>
            <LONG>-0.110000</LONG>
            <MEDIUMIMAGE>1</MEDIUMIMAGE>
            <MEDIUMIMAGEBAR>0</MEDIUMIMAGEBAR>
            <NAME>Angel Curry Centre</NAME>
            <NUMOFFERS></NUMOFFERS>
            <ORDERNAME>angelcurrycentre</ORDERNAME>
            <POSTCODE>N1 9EZ</POSTCODE>
            <SCORE>score</SCORE>
            <SMALLIMAGE>1</SMALLIMAGE>
            <SMALLIMAGEBAR>0</SMALLIMAGEBAR>
            <TXTREVIEW>&lt;b&gt;toptable Dining Awards 2009 - Runner Up: Best Value &amp; Best for Dining with friends &lt;/b&gt;&lt;BR&gt;&lt;BR&gt;Despite the name, Angel Curry Centre is actually a small and perfectly elegant modern Indian. Neither short on competition nor regulars, its success is right where it should be  in the consistency of...</TXTREVIEW>
            </result>
            
            <result>
            <ADDRESS1>58 Stoke Newington Church Street</ADDRESS1><ADDRESS2></ADDRESS2><ADDRESS3></ADDRESS3><AVGPRICE>&#xa3;24 and under</AVGPRICE><BOOKINGS>0</BOOKINGS><CITY>London</CITY><COUNTRY>United Kingdom</COUNTRY><COUNTY></COUNTY><COVERS>0</COVERS><CUISINE>Thai</CUISINE><ID>4196</ID><LARGEIMAGE>1</LARGEIMAGE><LARGEIMAGEBAR>0</LARGEIMAGEBAR><LAT>51.562320</LAT><LOCATION></LOCATION><LONG>-0.076140</LONG><MEDIUMIMAGE>1</MEDIUMIMAGE><MEDIUMIMAGEBAR>0</MEDIUMIMAGEBAR><NAME>Lemongrass</NAME><NUMOFFERS></NUMOFFERS><ORDERNAME>lemongrass</ORDERNAME><POSTCODE>N16 0NB</POSTCODE><SCORE>score</SCORE><SMALLIMAGE>1</SMALLIMAGE><SMALLIMAGEBAR>0</SMALLIMAGEBAR><TXTREVIEW>Lemongrass restaurant in Stoke Newingtons most vibrant street is a stylish, upmarket purveyor of Thai cuisine both traditional and modern. The urban chic d&#xe9;cor is a soothing blend of natural wood with azure blue and creamy yellow. Theres sleek modern seating and lighting and a very cool chrome...</TXTREVIEW>
            </result>
            
            <result>
            <ADDRESS1>392 Green Lanes</ADDRESS1><ADDRESS2></ADDRESS2><ADDRESS3></ADDRESS3><AVGPRICE>&#xa3;25 - &#xa3;34</AVGPRICE><BOOKINGS>0</BOOKINGS><CITY>London</CITY><COUNTRY>United Kingdom</COUNTRY><COUNTY></COUNTY><COVERS>0</COVERS><CUISINE>Indian</CUISINE><ID>4552</ID><LARGEIMAGE>1</LARGEIMAGE><LARGEIMAGEBAR>0</LARGEIMAGEBAR><LAT>51.621260</LAT><LOCATION></LOCATION><LONG>-0.105610</LONG><MEDIUMIMAGE>1</MEDIUMIMAGE><MEDIUMIMAGEBAR>0</MEDIUMIMAGEBAR><NAME>Shamiana Indian Restaurant</NAME><NUMOFFERS></NUMOFFERS><ORDERNAME>shamianaindianrestaurant</ORDERNAME><POSTCODE>N13 5PD</POSTCODE><SCORE>score</SCORE><SMALLIMAGE>1</SMALLIMAGE><SMALLIMAGEBAR>0</SMALLIMAGEBAR><TXTREVIEW>Theres nothing quite like discovering a great Indian in your neighbourhood, and residents of Palmers Green have certainly got the lock on that. Shamiana Indian Restaurant is a comfortable, locally-loved establishment, serving both old standards and new interpretations of classic regional Indian...</TXTREVIEW>
            </result>
            
            </root>
 
            [totalResultsAvailable] => 4.0
        )
 
)

Open in new window

0
 
Ray PaseurCommented:
Looking at that, it appears you can find two meaningful values in the sub-array called runQuickReturn.  The XML you want to load with SimpleXML is in array["runQuickReturn"]["resultsAsXml"] and the number of things to expect to find in the XML appears to be in array["runQuickReturn"]["totalResultsAvailable"] -- not sure why that is a decimal number.

Does that help? ~Ray
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now