title: Find closest longitude and latitude in array?
body: <p>I have a longitude and latitude as a string in PHP like below</p>
  
  <pre><code>49.648881
  -103.575312
  </code></pre>
  
  <p>And I want to take that and look in an array of values to find the closest one. The array looks like</p>
  
  <pre><code>array(
  '0'=&gt;array('item1','otheritem1details....','55.645645','-42.5323'),
  '1'=&gt;array('item1','otheritem1details....','100.645645','-402.5323')
  );
  </code></pre>
  
  <p>I want to return the array that has the closest long and lad. In this case it would be the first one (and yes I know -400 is not a a possible value).</p>
  
  <p>Is there any quick and easy way to do this? I tried array searching but that didn't work.</p>
  
  <p>Difference code</p>
  
  <pre><code>function distance($lat1, $lon1, $lat2, $lon2, $unit) { 
  
    $theta = $lon1 - $lon2; 
    $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) +  cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta)); 
    $dist = acos($dist); 
    $dist = rad2deg($dist); 
    $miles = $dist * 60 * 1.1515;
    $unit = strtoupper($unit);
  
    if ($unit == "K") {
      return ($miles * 1.609344); 
    } else if ($unit == "N") {
        return ($miles * 0.8684);
      } else {
          return $miles;
        }
  }
  </code></pre>