创建一个多维数组,点是第一个键,胜利是第二个键,php 会自动按键对它们进行排序。
<?php
//each array with (Teams, Points, Wins)
$rank[] = array('Team' => "A", 'Points' => 24, 'Wins' => 11);
$rank[] = array('Team' => "B", 'Points' => 26, 'Wins' => 11);
$rank[] = array('Team' => "C", 'Points' => 25, 'Wins' => 10);
$rank[] = array('Team' => "D", 'Points' => 24, 'Wins' => 12);
$rank[] = array('Team' => "E", 'Points' => 25, 'Wins' => 11);
$rank[] = array('Team' => "F", 'Points' => 27, 'Wins' => 13);
foreach ($rank as $key => $row) {
$points[$key] = $row['Points'];
$wins[$key] = $row['Wins'];
}
array_multisort($points, SORT_DESC, $wins, SORT_DESC, $rank);
echo "<ol>";
for ($line = 0; $line < 6; $line++){
echo "<li><b> Rank</b>";
foreach($rank[$line] as $key => $value){
echo "|".$key."-".$value."|";
}
echo "</li>";
}
echo "</ol>";
?>