json - Codeigniter PHP - Parse SOAP (WDSL) result -


i retrieving information web service using:

$servicedata= new soapclient('http://xxx.xxx.xxx.xx:xx/webservice/webservice.svc?wsdl'); $response = $servicedata->getmyinformation(); var_dump($response); 

the result var_dump below:

object(stdclass)#15 (1)  { ["getdatabaseresult"]=> object(stdclass)#16 (1)     { ["databaseinformation"]=> array(4)           {   [0]=> object(stdclass)#17 (2)              { ["datecreated"]=> string(19) "2016-07-06t09:36:03" ["currencycode"]=> string(3) "usd" }               [1]=> object(stdclass)#18 (2)              { ["datecreated"]=> string(19) "2016-12-07t02:49:02" ["currencycode"]=> string(3) "usd" }               [2]=> object(stdclass)#19 (2)              { ["datecreated"]=> string(19) "2016-12-07t02:52:38" ["currencycode"]=> string(3) "usd" }               [3]=> object(stdclass)#20 (2)              { ["datecreated"]=> string(19) "2016-12-07t02:53:38" ["currencycode"]=> string(3) "usd" }          }     } } 

what need foreach loop can retrieve each key , value:

datecreated: 2016-07-06t09:36:03 currencycode: usd 

i tried using json_encode($response) removed object(stdclass)#15 (1) , json_dencode($response) got point:

array(1)  { ["getdatabaseresult"]=> array(1)      { ["databaseinformation"]=> array(4)          {   [0]=> array(2)              { ["datecreated"]=> string(19) "2016-07-06t09:36:03" ["currencycode"]=> string(3) "usd" }              [1]=> array(17)              { ["datecreated"]=> string(19) "2016-12-07t02:49:02" ["currencycode"]=> string(3) "usd" }               [2]=> array(17)              { ["datecreated"]=> string(19) "2016-12-07t02:52:38" ["currencycode"]=> string(3) "usd" }              [3]=> array(17)              { ["datecreated"]=> string(19) "2016-12-07t02:52:38" ["currencycode"]=> string(3) "usd" }          }     } } 

i know it's nested array, how parse it?

no need encode/decode loop. try this:

foreach($response->getdatabaseresult->databaseinformation $entry){   error_log("date created: ".$entry->datecreated."; currency code: ".$entry->currencycode); } 

Comments