0

Hi I am using php to get data from wunderground weather api, unfortunately I get error message "Notice: Array to string" when one of them is empty. On the sample code below I am trying to display alert if the api has one and empty when their is none data but instead I get "Notice: Array to string". Same thing with hurricane if the api has data then it shows the name of the hurricane but if their is none I get the error as well.

Can you please advice the best way to fix the issue.

$string = file_get_contents("http://api.wunderground.com/api/52783a7a5b62dac5.json");
$json_decoded = json_decode($string,true);

$location_UV = $json_decoded['current_observation']['UV'];
$location_hurricane = $json_decoded['currenthurricane']['stormInfo']['stormName_Nice'];
$location_alert = $json_decoded['alerts'];

<p><?php echo "$location_UV";?></p>
<p><?php echo "$location_hurricane";?></p>
<p><?php echo "$location_alert";?></p>

Many thanks

2
  • can you do var_dump($location_hurricane) when there is no data and post the result?
    – Himan
    Commented Sep 29, 2017 at 14:05
  • Thanks, found a solution =)
    – James Tan
    Commented Oct 6, 2017 at 14:47

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.