Pages

Search This Blog

Sunday, September 27, 2009

phpsoap: retrieve returned array data

Well, i'm newbie in soap especially phpsoap. I'm facing problem to retrieve data returned from a soap api written in .net. I can see the whole data printed out by using print_r but i'm not able to get the each data from the array returned.

Situation:
I want to get the data returned by the soap server in array form after i've called the function "GetAccountInfo" by passing in parameter "AccoundID" by using phpsoap client.
My soap server url: http://10.10.100.101/soapserver.asmx

below are the code that i can get the data printed out.
<?php
$ini = ini_set("soap.wsdl_cache_enabled","0");

//instantiate the SOAP client
$client = new SoapClient("http://10.10.100.101/soapserver.asmx?WSDL");

$params = array();
$params["AccountID"] = "inblues";

$result = $client->GetAccountInfo($params);
print_r ($result ->GetAccountInfoResult);

?>

Output on the browser:


Array (
[GetAccountInfoResult] => Array (
[memberData] => Array (
[lastlogin] => 6/19/2009 2:10:51 AM
[lastip] => 219.95.192.254
[datecreated] => 6/19/2009 2:10:51 AM
[active] => 1
)
)
)



But what i want is only [active] field's data. What can i do? Finally, by looking at the printed result and by try and error, i found out that it's a 3 dimensional array, below code helps me to get the data i want.

<?php
$ini = ini_set("soap.wsdl_cache_enabled","0");

//instantiate the SOAP client
$client = new SoapClient("http://10.10.100.101/soapserver.asmx?WSDL");

$params = array();
$params["AccountID"] = "inblues";

$result = $client->GetAccountInfo($params);

// the result is in 3 dimensional array
print_r ($result->GetAccountInfoResult->memberData-> active);

?>

Solve. I get my value 1 printed out in the browser.

No comments: