<?php
function calculateRoutes($points){
//our output array
$out = array();
//reset the index of our points to ensure they are 0 to N-1
$points = array_values($points);
//loop over the points once
for($i=0; $i<count($points) - 1; $i++){
//loop over the points again, offset by 1
for($j=$i+1; $j<count($points); $j++){
//add to our output array the two points
$out[] = array($points[$i], $points[$j]);
}
}
//return the final result
return $out;
}
$points = array('A', 'B', 'C', 'D');
$routes = calculateRoutes($points);
print_r($routes);