Jump to content

extracting data from an API array


swingking

Recommended Posts

I have been banging my head against the wall trying to pull out data from a returned array from the Hitslink API.

here is the code that returns the data....

$params = array("account" => $username, // Create a wrapper array for SOAP params
  "password" => $password,
  "reportId" => $reportID,
  "maxRows"  => $maxRows,
  "chartHeight"  => $chartHeight,
  "chartWidth"  => $chartWidth);

// Instantiate the soapclient, pass it the WSDL location
$client = new soapclient("http://www.hitslink.com/reportWS.asmx?WSDL");


    // Call the GetData WS Function, parse and display to taste.
    $return = $client->GetData($params);
   

I added this to display the data....
while (list ($key, $val) = each ($return->GetDataResult)) {
echo "$key -> $val <br>";
}

and here is the results displayed...

Title -> Traffic History
EndDate -> 2006-11-27T14:00:00
StartDate -> 2006-11-26T15:00:00
ChartURL -> www.hitslink.com/chartfx62/temp/cft1127_03300129f56.png
ColumnDefinitions -> Object id #4
Rows -> Object id #11

What I want is the "Rows" data.

how do I extract this info into an array?

thanks!

Mark
[email protected]
Link to comment
https://forums.phpfreaks.com/topic/28653-extracting-data-from-an-api-array/
Share on other sites

You do it like you did the first object [b]$return->GetDataResult[/b], inside that loop you test [code]$v[/code] to see if it is another object, if it is you loop that object too!


This is just a simple example, if your object have more child obects then you will need to add some type of recursion!


[code] foreach ( $return->GetDataResult AS $pk => $pv )
{
if ( is_obj ( $pv ) )
{
echo $pk . ":<br />";

foreach ( $pv AS $ck => $cv )
{
echo "\t" . $ck . " -> " . $cv . "<br />";
}
}
else
{
echo $pk . " -> " . $pv . "<br />";
}
}[/code]


printf

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.