PHP auto compute multidimensional arrays against one another : <p>I have a multidimensional array.</p>

<pre><code>$parent_array($child1('lat','long'),$child2('lat','long')...)
</code></pre>

<p>The amount of child arrays can be of any value per request starting from 2.
The parent array is then called into a function that has a google distance calculator between to or more points.</p>

<pre><code>function distance($parent_array)
{
    foreach ( $parent_array as $child){
        $distance =  file_get_contents('https://maps.googleapis.com/maps/api/distancematrix/json?units=metric&amp;origins='.$child1['lat'].','.$child1['long'].'&amp;destinations='.$child2['lat'].','.$child2['long'].'&amp;key=********************************');
        $trim = trim($this-&gt;objectToArray($distance)['rows'][0]['elements'][0]['distance']['text'],' km');

    }

    return $trim;
}
</code></pre>

<p>I need to get this function to calculate the distance between all posted child arrays as illustrated on the above function using </p>

<blockquote>
  <p>$child1 and $child2</p>
</blockquote>
