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 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?