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:

我从Twitter API中检索了一系列对象,我想总结一下。我最熟悉的是从SQL查询中分析结果,但给出了一系列这样的对象:

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/">web</a>" 
            ["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?

是否有可能以某种方式说“对于每个对象'from_user = $ whoever',计算'text'字段,减去#runlogger”?一旦我掌握了大规模的想法,我就可以弄清楚代码,但我不确定如何以一般方式开始。我会将'text'字段的每个实例设置为变量,然后将这些变量添加到数组中吗?

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

我是一个快速学习,但在这个问题上会喜欢一些指导。

Thanks!

1 个解决方案

#1


Assume that you assign this to an array $array1

假设您将其分配给数组$ array1

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

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

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

         $strText .= $strippedTexts[0];

     }

}

echo $strText;

regards

更多相关文章

  1. 电商网站项目总结(面向对象编程篇)
  2. 为什么我对JSON对象的AJAX调用会返回其特定内容的未定义?
  3. php对象的实现
  4. PHP:将simpleXML对象转换为二维数组
  5. 如何对继承对象进行单元测试?
  6. PHP中类和对象的相关函数
  7. 【PHP面向对象(OOP)编程入门教程】15.static和const关键字的使用
  8. PHP面向对象笔记 —— 113 封装概念
  9. 如果使用Select2 YII2选择第一个字段,请在下方自动填充字段

随机推荐

  1. Fedora写给Python的情书
  2. 值得关注的5个Python开源项目
  3. 2分钟理清计算机、Python和Pip的三角关系
  4. 用Python制作3D动画
  5. 如果你也用Win10,真的请备份!
  6. 不看教程,可能更浪费你的时间
  7. 在python中执行shell命令的6种方法
  8. 临摹源码 | 一比一手写Dubbo源码中的SPI(
  9. 最良心的Python安装说明
  10. 小编的2017年度计划及最近改变