Челябинск
Магнитогорск
Миасс
Златоуст
Снежинск
Троицк
Карабаш
Еманжелинск
Аша
Локомотивный
....
foreach($A['cities'] as $v1){
foreach($A['cities'] as $v2){
if($v1==$v2) continue;
$s1 = $v1.''.$v2;
$s2 = $v2.''.$v1;
if(in_array($s1, $A['index'] ) || in_array($s2, $A['index'] )) continue;
$A['pairs'][] = array($v1,$v2);
$A['index'][] = $s1;
$A['index'][] = $s2;
}
}
<?php
$array = array('Челябинск','Магнитогорск', 'Миасс','Златоуст');
$result_array = array();
$tmp_pairs = array();
foreach( $array as $row => $town_in_row )
{
foreach( $array as $column => $town_in_column )
{
if( $column == $row )
continue;
$pairs_key1 = $row.'_'. $column;
$pairs_key2 = $column .'_'. $row;
if( isset($pairs[$pairs_key1]) or isset($pairs[$pairs_key2]) )
continue;
$result_array[] = $town_in_row .'-'.$town_in_column;
$pairs[$pairs_key1] = true;
}
}
print_r($result_array);