0

I use Openweather API and I have a result is like this:

$al = json_decode($cikti,false); // RESULT IS BELOW
stdClass Object ( [coord] => stdClass Object ( [lon] => 27.0923 [lat] => 38.4622 ) [weather] => Array ( [0] => stdClass Object ( [id] => 802 [main] => Clouds [description] => parçalı az bulutlu [icon] => 03n ) ) [base] => stations [main] => stdClass Object ( [temp] => 24.97 [feels_like] => 24.83 [temp_min] => 24.73 [temp_max] => 24.97 [pressure] => 1011 [humidity] => 50 ) [visibility] => 10000 [wind] => stdClass Object ( [speed] => 2.57 [deg] => 290 ) [clouds] => stdClass Object ( [all] => 40 ) [dt] => 1652896065 [sys] => stdClass Object ( [type] => 1 [id] => 6979 [country] => TR [sunrise] => 1652842682 [sunset] => 1652894299 ) [timezone] => 10800 [id] => 311044 [name] => İzmir [cod] => 200 )

When I use

<?= $al->main->temp ?>

I can access temputure data but when I need to description belongs to Clouds I have an error. I try to :

$al->weather[0]->main It is result Clouds but it is a string. I can not get Clouds->description or Clouds["description"] so how can I solve this problem and how can I access all data from API response?

  • You're reading it wrong. If you post the json, you'll see that weather is an array. The first array (key 0) is an object with a property of main that equals 'Clouds', and a property of description that contains `parçalı az bulutlu`. So it should be `$al->weather[0]->description` – aynber May 18 '22 at 18:08

0 Answers0