如何使用javascript将数组存储到php文件中

I need something similar to the code we have where we alert the coordinates but instead save those coordinates into a php file.

 var array = [];
          navigator.geolocation.getCurrentPosition(function(position) {
            var lat = position.coords.latitude;
            var lon = position.coords.longitude;
               array.push(lat, lon); 
                locationCode()         

});

function locationCode() {
   alert(array); 
}                // Try HTML5 geolocation.
        if (navigator.geolocation) {
          navigator.geolocation.getCurrentPosition(function(position) {
            var pos = {
              lat: position.coords.latitude,
            lng: position.coords.longitude

               };