dongwo8827523 2015-10-22 08:51
浏览 50
已采纳

如何从这个php数组中获取值[重复]

This question already has an answer here:

i have this array from json_decode

stdClass Object ( 
         [coord] => stdClass Object ( 
                             [lon] => 8.97 
                             [lat] => 51 
                            ) 
         [weather] => Array ( 
                          [0] => stdClass Object ( 
                               [id] => 804 
                               [main] => Clouds 
                               [description] => overcast clouds 
                               [icon] => 04d 
                             ) 
                         ) 
          [base] => stations 
          [main] => stdClass Object ( 
                        [temp] => 281.17 
                        [pressure] => 1014 
                        [humidity] => 87 
                        [temp_min] => 280.93 
                        [temp_max] => 281.48 
                       ) 
           [visibility] => 7000 
           [wind] => stdClass Object ( 
                        [speed] => 3.6 
                        [deg] => 180 
                      ) 
           [clouds] => stdClass Object ( 
                        [all] => 90 
                      ) 
           [dt] => 1445499854 
           [sys] => stdClass Object ( 
                        [type] => 1 
                        [id] => 4954 
                        [message] => 0.0056 
                        [country] => DE 
                        [sunrise] => 1445493535 
                        [sunset] => 1445530644 
                       ) 
            [id] => 2906244 
            [name] => Herbelhausen 
            [cod] => 200 
         )

i have get from it the description

$response_a2->weather[0]->description

but wen am trying to get the temp or pressure or humidity or speed i filed

$response_a2->base->temp
</div>
  • 写回答

3条回答 默认 最新

  • doubi2228 2015-10-22 09:01
    关注

    You are looking for

    $response_a2->main->temp
    

    Thanks to RiggsFolly for beautifying the array.

    next time, write your code like this:

    echo "<pre">;
    print_r($response_a2);
    echo "</pre>";
    

    and your array will look beautiful in the browser

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥15 DruidDataSource一直closing
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据