# Sort array, change subsequent key sort direction?

Using PHP & MySql, I have:

\$record[\$teamid] = array(‘wins’=>\$wins, ‘losses’=>\$losses, ‘ties’=>\$ties);

Example for TeamA, TeamB, TeamC in array:

record[0] = [2, 1, 0];
record[1] = [2, 0, 0];
record[2] = [3, 0, 0];

When I print the output using arsort(\$record), I get:

TeamC 3-0-0
TeamA 2-1-0
TeamB 2-0-0

because it is sorting from high-to-low starting with the wins, then losses, then ties.

Since 2-1-0 is a worse win % than 2-0, I want the output to be:

TeamC 3-0-0
TeamB 2-0-0
TeamA 2-1-0

Is there a way to specify that ‘losses’ be sorted from low-to-high?

Thank you for your time.

Shamelessly poached from manual page on multisort

``````

// renamed keys so that success should show TeamA, B, C in correct order

\$record['TeamC'] = array(2, 1, 0); // bottom team, they had a loss
\$record['TeamB'] = array(2, 0, 0);
\$record['TeamA'] = array(3, 0, 0);  // top team

// Obtain a list of columns
foreach (\$record as \$key => \$row) {
\$wins[\$key]  = \$row[0];
\$losses[\$key] = \$row[1];
}

// Sort the data with volume descending, edition ascending
// Add \$data as the last parameter, to sort by the common key

array_multisort(\$wins, SORT_DESC, \$losses, SORT_ASC, \$record);

var_dump(\$record);

// gives, TeamA, B, C:

array
'TeamA' =>
array
0 => int 3
1 => int 0
2 => int 0
'TeamB' =>
array
0 => int 2
1 => int 0
2 => int 0
'TeamC' =>
array
0 => int 2
1 => int 1
2 => int 0

``````

Thank you…will give it a shot!