title: PHP - Find the Median of Array with Latitude Longitude
body: <p>I have an array of locations with latitude and longitude values and would like to find the location in the array of which its coordinates are in the middle (the <strong>median</strong>). Assume that I have an array that looks like this:</p>
  
  <pre><code>$location = [];
  $location[0] = [];
  $location[0]['name'] = 'Valencia';
  $location[0]['latitude'] = 39.46990750;
  $location[0]['longitude'] = -0.37628810;
  $location[1] = [];
  $location[1]['name'] = 'Alanya';
  $location[1]['latitude'] = 36.54444300;
  $location[1]['longitude'] = 31.99540800;
  $location[2] = [];
  $location[2]['name'] = 'Side';
  $location[2]['latitude'] = 36.77687300;
  $location[2]['longitude'] = 31.39764400;
  $location[2] = [];
  $location[3]['name'] = 'Miami';
  $location[3]['latitude'] = 25.79065400;
  $location[3]['longitude'] = -80.13004550;
  $location[4] = [];
  $location[4]['name'] = 'Albufeira';
  $location[4]['latitude'] = 37.08907190;
  $location[4]['longitude'] = -8.24787960;
  </code></pre>
  
  <p>How can I calculate the median of the latitude/longitude and find the name of the associated location using PHP?</p>