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