1

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.

zod
  • 12,092
  • 24
  • 70
  • 106
Jeremy Harris
  • 24,318
  • 13
  • 79
  • 133
  • Can you repost the `var_dump()` as it appears (with linebreaks and indentation) when you view source on the page? Too difficult to read in a block like this – Michael Berkowski Aug 22 '11 at 18:16
  • I didn't realize the dump looked different in the source. I was looking at that tangled mess trying to pick it apart. LOL. Still don't know how to separate it as a usable array though. – Jeremy Harris Aug 22 '11 at 18:24

1 Answers1

3

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;
cwallenpoole
  • 79,954
  • 26
  • 128
  • 166