Tuesday, 27 August 2013

Read array in case of catch exception

Read array in case of catch exception

In case of catch (Exception $e) , the following code fails at the line
$lat = $track[0]. How to fix it?
$track = getPositionalTrack();
$lat = $track[0];
$lon = $track[1];
function getPositionalTrack()
{
$track = array();
$url = "https://...";
try
{
$result = file_get_contents($url);
$obj = json_decode($result, true);
$lat = $obj["lat"];
$lon = $obj["lon"];
$track[0] = $lat;
$track[1] = $lon;
}
catch (Exception $e)
{
die('ERROR: ' . $e->getMessage());
}
return $track;
}

No comments:

Post a Comment