3v4l.org

run code in 300+ PHP versions simultaneously
<?php function array_alternate_multisort($array, ...$args) { foreach ($args as $i => $arg) { $sortParams[] = $i & 1 ? $arg : array_column($array, $arg); } $sortParams[] = &$array; array_multisort(...$sortParams); return $array; } $alliances = [ ['id' => 1, 'output' => '1', 'score' => 10], ['id' => 2, 'output' => '0', 'score' => 9], ['id' => 3, 'output' => '1', 'score' => 11], ['id' => 4, 'output' => '1', 'score' => 9], ['id' => 5, 'output' => '0', 'score' => 10], ]; $alliances = array_alternate_multisort($alliances, "output", SORT_DESC, "score", SORT_DESC); var_export($alliances);

preferences:
24.65 ms | 406 KiB | 5 Q