I am writing a little web app for ocean tides using PHP. I am having problems figuring out how to access the array returned (which PHP converted to a stdObject).
The WSDL file is located at: http://opendap.co-ops.nos.noaa.gov/axis/webservices/highlowtidepred/wsdl/HighLowTidePred.wsdl
My PHP code is:
$wsdl = "http://opendap.co-ops.nos.noaa.gov/axis/webservices/highlowtidepred/wsdl/HighLowTidePred.wsdl";
$tides = new soapclient($wsdl);
$tideParams = array(
'stationId' => '8454000',
'beginDate' => '20110821 00:00',
'endDate' => '20110821 23:59',
'datum' => '0',
'unit' => '0',
'timeZone' => '0'
);
$tideRet = $tides->getHighLowTidePredictions($tideParams);
var_dump($tideRet);
This dum开发者_运维知识库p returns:
object(stdClass)#2 (1) {
["HighLowValues"]=>
object(stdClass)#3 (1) {
["item"]=>
object(stdClass)#4 (2) {
["data"]=>
array(4) {
[0]=>
object(stdClass)#5 (3) {
["time"]=>
string(5) "00:35"
["pred"]=>
float(3.8)
["type"]=>
string(1) "H"
}
[1]=>
object(stdClass)#6 (3) {
["time"]=>
string(5) "05:45"
["pred"]=>
float(0.7)
["type"]=>
string(1) "L"
}
[2]=>
object(stdClass)#7 (3) {
["time"]=>
string(5) "12:49"
["pred"]=>
float(4.2)
["type"]=>
string(1) "H"
}
[3]=>
object(stdClass)#8 (3) {
["time"]=>
string(5) "18:32"
["pred"]=>
float(1.3)
["type"]=>
string(1) "L"
}
}
["date"]=>
string(10) "08/21/2011"
}
}
}
I have no idea how to read into this and my googling hasn't helped much either. Any help or direction is appreciated.
That is a dynamic PHP object. All of the quoted items are property names, so to get to the data array:
$data = $tides->getHighLowTidePredictions($tideParams)
->HighLowValues
->item
->data;
Then, if you want to get a particular item's time property, for example, you would address that array index and look up the time property:
$data[0]->time;
精彩评论