swingking Posted November 27, 2006 Share Posted November 27, 2006 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 HistoryEndDate -> 2006-11-27T14:00:00StartDate -> 2006-11-26T15:00:00ChartURL -> www.hitslink.com/chartfx62/temp/cft1127_03300129f56.pngColumnDefinitions -> Object id #4Rows -> 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 More sharing options...
trq Posted November 27, 2006 Share Posted November 27, 2006 [quote]how do I extract this info into an array?[/quote]You don't, its an object. Surely this API has some documentation. Maybe the object has a method to iterate over its properties. Link to comment https://forums.phpfreaks.com/topic/28653-extracting-data-from-an-api-array/#findComment-131124 Share on other sites More sharing options...
swingking Posted November 27, 2006 Author Share Posted November 27, 2006 ok. how do you take the information from an object and cycle through and parse the data? sorry, I am a newbie in over it's head. Link to comment https://forums.phpfreaks.com/topic/28653-extracting-data-from-an-api-array/#findComment-131130 Share on other sites More sharing options...
printf Posted November 27, 2006 Share Posted November 27, 2006 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 Link to comment https://forums.phpfreaks.com/topic/28653-extracting-data-from-an-api-array/#findComment-131150 Share on other sites More sharing options...
swingking Posted November 27, 2006 Author Share Posted November 27, 2006 do you mean objects within objects? my head is swirling!!I am so confused.would there be ANY way you can show me sample code to do this? printf, your help is VERY appreciated! Link to comment https://forums.phpfreaks.com/topic/28653-extracting-data-from-an-api-array/#findComment-131189 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.