Google map mileage function to return mileage between to addresses : For each loop quit working. 

    public static function getMiles($to, $from)
    {
    
        $from = urlencode($from);
        $to = urlencode($to);
        $data = file_get_contents("https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial&origins=$from&destinations=$to&key=AIzaSyAX8D-kve7_xjQSkJP2tF_o2LxNl2McTNc");
    
        $time = 0;
        $distance = 0;

        /* return as an object for easier notation */
        $json=json_decode( $data, false );
        $origins = $json->origin_addresses;
        $destinations=$json->destination_addresses;
       
        /*  if there are multiple rows, use a loop and `$rows[$i]` etc */
        $elements=$json->rows[0]->elements;
        
            foreach( $elements as $i => $obj ){
            } 
        //extract the mileage as meters
        $miles = $obj->distance->value;
        
        //converting the meters to miles
        $distance= round(($miles * '0.000621371192'), 1);
        //returning miles
        return $distance;
    
    }

The end result is to return mileage between 2 addresses. 
Error message is "'Invalid argument supplied for foreach()'"