帮助从 SOAP 响应中找出嵌套数组?

发布于 2024-11-30 14:30:14 字数 2171 浏览 1 评论 0原文

我正在使用 PHP 编写一个用于海洋潮汐的小网络应用程序。我在弄清楚如何访问返回的数组(PHP 将其转换为 stdObject)时遇到问题。

WSDL 文件位于:http://opendap.co-ops.nos.noaa.gov/axis/webservices/highlowtidepred/wsdl/HighLowTidePred.wsdl

我的 PHP 代码是:

    $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);

此转储返回:

   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 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 dump 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月亮是我掰弯的 2024-12-07 14:30:14

那是一个动态的 PHP 对象。所有引用的项目都是属性名称,因此要获取数据数组:

$data = $tides->getHighLowTidePredictions($tideParams)
              ->HighLowValues
              ->item
              ->data;

然后,如果您想获取特定项目的时间属性,例如,您可以寻址该数组索引并查找时间属性:

 $data[0]->time;

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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文