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);
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.30, 8.2.0 - 8.2.25, 8.3.0 - 8.3.13
array ( 0 => array ( 'id' => 3, 'output' => '1', 'score' => 11, ), 1 => array ( 'id' => 1, 'output' => '1', 'score' => 10, ), 2 => array ( 'id' => 4, 'output' => '1', 'score' => 9, ), 3 => array ( 'id' => 5, 'output' => '0', 'score' => 10, ), 4 => array ( 'id' => 2, 'output' => '0', 'score' => 9, ), )

preferences:
67.53 ms | 408 KiB | 5 Q