$v) { $base = $ans[$name]; $base['name'] = $name; $board[] = $base; } $people = count($board); for ($i = 0; $i < $people - 1; $i++) { for ($j = $i + 1; $j < $people; $j++) { $swap1 = $board[$i]['score'] < $board[$j]['score']; $swap2a = $board[$i]['score'] == $board[$j]['score']; $swap2b = $board[$i]['lastmod'] > $board[$j]['lastmod']; if ($swap1 || ($swap2a && $swap2b)) { list($board[$i], $board[$j]) = array($board[$j], $board[$i]); } } } $output = ""; for ($i = 0; $i < $people; $i++) { $output .= $i + 1; $output .= " "; $output .= $board[$i]['name']; $output .= " "; for ($j = 0; $j < $cntL; $j++) { $output .= $board[$i][$j] ?: 0; $output .= " "; } $output .= $board[$i]['score']; $output .= PHP_EOL; } echo $output; // echo (microtime(true) - $Tim) . PHP_EOL;