Get latitude and longitude from zip code using PHP

Course- PHP Tutorial >

The following PHP function will generate Latitude and Longitude from given zip code.

function getLnt($zip){
$url = "//maps.googleapis.com/maps/api/geocode/json?address=
".urlencode($zip)."&sensor=false";
$result_string = file_get_contents($url);
$result = json_decode($result_string, true);
$result1[]=$result['results'][0];
$result2[]=$result1[0]['geometry'];
$result3[]=$result2[0]['location'];
return $result3[0];
}


To display output:

<?php
 $val = getLnt('90001');
 echo "Latitude: ".$val['lat']."<br>";
 echo "Longitude: ".$val['lng']."<br>";
?>