tags:

views:

103

answers:

1

Hi there,

I've retrieved a series of objects from the Twitter API, and I want to summarize them. I'm most familiar with analyzing results from a SQL query, but given a series of objects like this:

array(9) { 
    ["results"]=> array(1) { 
     [0]=> array(9) { 
      ["text"]=> string(14) "4.2 #runlogger" 
      ["to_user_id"]=> NULL 
      ["from_user"]=> string(13) "alexmcpherson" 
      ["id"]=> int(1459499489) 
      ["from_user_id"]=> int(4647988) 
      ["iso_language_code"]=> string(2) "it" 
      ["source"]=> string(59) "<a href="http://twitter.com/"&gt;web&lt;/a&gt;" 
      ["profile_image_url"]=> string(59) "http://static.twitter.com/images/default_profile_normal.png" 
      ["created_at"]=> string(31) "Sun, 05 Apr 2009 23:10:45 +0000" 
      } } 
["since_id"]=> int(0)
["max_id"]=> int(1461841556) 
["refresh_url"]=> string(35) "?since_id=1461841556&q=%23runlogger" 
["results_per_page"]=> int(15) 
["total"]=> int(1) 
["completed_in"]=> float(0.073063) 
["page"]=> int(1) 
["query"]=> string(12) "%23runlogger" 
}

Would it be possible to somehow say "for each object where 'from_user=$whoever', tally up the 'text' field, minus the #runlogger"? I can figure out the code once I have the large-scale idea I think, but am not sure how to start in a general way. Would I set each instance of the 'text' field to a variable, then add those variables into an array or something?

I'm a quick study, but would love some guidance in this problem.

Thanks!

+2  A: 

Hi

Assume that you assign this to an array $array1

foreach($array1['results'] as $currentResult) {

     if($currentResult['from_user'] == $whoever) {

         $strippedTexts = explode(" ", $currentResult['text']);

         $strText .= $strippedTexts[0];

     }

}

echo $strText;

regards

uuɐɯǝʃǝs
Just perfect. Good code.
Alex Mcp