So I've got the following array: http://pastebin.com/raw.php?i=AazcQUbG
In a part of code outside of the function below, I loop through this particular ordered array (ordered by the second dimension's 'team_points') and determine if there is a tie in 'team_points'. If a tie in team_points is determined, I check the tie_breaker of each.
I want a first dimension order switch to take place if a tie exists and the tie_breaker of the second item in the first dimension is less than the first item's.
The following function is not forcing a switch. Can someone please help me figure out why I am unable to make the positions in the first dimension of this array switch and suggest a way to accomplish that?
function array_swap($key1, $key2, $array) {
$newArray = array ();
foreach ($array as $key => $value) {
if ($key == $key1) {
$newArray[$key2] = $array[$key2];
} elseif ($key == $key2) {
$newArray[$key1] = $array[$key1];
} else {
$newArray[$key] = $value;
}
}
return $newArray;
}