将php数组解析为整数

时间:2014-04-14 07:52:22

标签: arrays

我通过twitters api连接

vardump将输出此数组,这就是我尝试格式化的内容。

array (size=1)
  0 => 
    object(stdClass)[22]
      public 'id' => float 2436756770
      public 'id_str' => string '2436756770' (length=10)
      public 'name' => string 'nGx2 Gaming' (length=11)
      public 'screen_name' => string 'nGx2Gaming' (length=10)
      public 'location' => string 'USA' (length=3)
      public 'description' => string '' (length=0)
      public 'url' => string 'http://t.co/NsLaDZ5tyT' (length=22)
      public 'entities' => 
        object(stdClass)[23]
          public 'url' => 
            object(stdClass)[24]
              ...
          public 'description' => 
            object(stdClass)[26]
              ...
      public 'protected' => boolean false
      public 'followers_count' => int 9
      public 'friends_count' => int 11
      public 'listed_count' => int 0
      public 'created_at' => string 'Thu Apr 10 09:15:18 +0000 2014' (length=30)
      public 'favourites_count' => int 0
      public 'utc_offset' => null
      public 'time_zone' => null
      public 'geo_enabled' => boolean false
      public 'verified' => boolean false
      public 'statuses_count' => int 62
      public 'lang' => string 'en' (length=2)
      public 'status' => 
        object(stdClass)[27]
          public 'created_at' => string 'Sat Apr 12 06:22:13 +0000 2014' (length=30)
          public 'id' => float 4.5486706364371E+17
          public 'id_str' => string '454867063643709440' (length=18)
          public 'text' => string 'Beachhead plans to test out new time slots for Diamond Division; new 'Battle Royale' ... - http://t.co/Sh3pD8BAqG http://t.co/rMKGUIJOTM' (length=136)
          public 'source' => string '<a href="http://ngx2gaming.com/" rel="nofollow">ngx2gaming.com Feed</a>' (length=71)
          public 'truncated' => boolean false
          public 'in_reply_to_status_id' => null
          public 'in_reply_to_status_id_str' => null
          public 'in_reply_to_user_id' => null
          public 'in_reply_to_user_id_str' => null
          public 'in_reply_to_screen_name' => null
          public 'geo' => null
          public 'coordinates' => null
          public 'place' => null
          public 'contributors' => null
          public 'retweet_count' => int 0
          public 'favorite_count' => int 0
          public 'entities' => 
            object(stdClass)[28]
              ...
          public 'favorited' => boolean false
          public 'retweeted' => boolean false
          public 'possibly_sensitive' => boolean false
          public 'lang' => string 'en' (length=2)
      public 'contributors_enabled' => boolean false
      public 'is_translator' => boolean false
      public 'is_translation_enabled' => boolean false
      public 'profile_background_color' => string '022330' (length=6)
      public 'profile_background_image_url' => string 'http://abs.twimg.com/images/themes/theme15/bg.png' (length=49)
      public 'profile_background_image_url_https' => string 'https://abs.twimg.com/images/themes/theme15/bg.png' (length=50)
      public 'profile_background_tile' => boolean false
      public 'profile_image_url' => string 'http://pbs.twimg.com/profile_images/454189459865485313/L980XBZk_normal.jpeg' (length=75)
      public 'profile_image_url_https' => string 'https://pbs.twimg.com/profile_images/454189459865485313/L980XBZk_normal.jpeg' (length=76)
      public 'profile_banner_url' => string 'https://pbs.twimg.com/profile_banners/2436756770/1397124533' (length=59)
      public 'profile_link_color' => string '0084B4' (length=6)
      public 'profile_sidebar_border_color' => string 'A8C7F7' (length=6)
      public 'profile_sidebar_fill_color' => string 'C0DFEC' (length=6)
      public 'profile_text_color' => string '333333' (length=6)
      public 'profile_use_background_image' => boolean true
      public 'default_profile' => boolean false
      public 'default_profile_image' => boolean false
      public 'following' => boolean false
      public 'follow_request_sent' => boolean false
      public 'notifications' => boolean false

我的问题是,我怎么能只回显一个字符串,比如说&#39; followers_count&#39;作为整数? 谢谢!

1 个答案:

答案 0 :(得分:0)

这些是嵌套数组和对象。 要获得followers_count,您需要:

$obj = $twitter_followers[0];
echo $obj->followers_count;