-4

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
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
unpitted.com
  • 54
  • 1
  • 9

3 Answers3

1

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

Tanuel Mategi
  • 1,253
  • 6
  • 13
0

That data does not exist in $response_a2->base->temp

Instead us

$response_a2->main->temp
$response_a2->main->presure
$response_a2->main->humidity

etc

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
0

What you are showing us is an object, not an array. Objects work differently from arrays. They use the -> operator to reach certain values.

For example, imagine I've got object $obj and I wanna reach value ['some_value'].

echo $obj->some_value;
Peter
  • 8,776
  • 6
  • 62
  • 95