Jump to content

uasort compare 3 or more values?


fanfavorite

Recommended Posts

I have a function that is used to rank teams.  It is as follows:

 

	function Compare_standings($ar1, $ar2){ 
	if ($ar1['pts']<$ar2['pts']) {
      			return 1;
	} else if ($ar1['pts']>$ar2['pts']) {
      			return -1;
	}
	if (in_array($ar1['id'],$ar2['teamsbeat'])) {
		return 1;
	} elseif (in_array($ar2['id'],$ar1['teamsbeat'])) {
		return -1;
	}
	if ($ar1['w']<$ar2['w']) {
	      	return 1;
	} else if ($ar1['w']>$ar2['w']) {
      		return -1;
	}
	if ($ar1['ga'] == 0) {
		$arg1 = 1;
	} else {
		$arg1 = $ar1['ga'];
	}
	if ($ar2['ga'] == 0) {
		$arg2 = 1;
	} else {
		$arg2 = $ar2['ga'];
	}
	if (($ar1['gf'] + $ar1['ga']) / $arg1 < ($ar2['gf'] + $ar2['ga']) / $arg2) {
	      	return 1;
	} elseif (($ar1['gf'] + $ar1['ga']) / $arg1 > ($ar2['gf'] + $ar2['ga']) / $arg2) {
      			return -1;
	}
   		return 0;
}

 

This all works perfect except at "if (in_array($ar1['id'],$ar2['teamsbeat'])) {", I need to check if any other teams in the array have the same amount of points (pts) and if they do, then if one of the tied teams has beaten all other tied teams, rank that team highest. 

 

I hope this is not too confusing.  I basically need to know if I can compare a 3rd value in this function somehow. 

 

Thanks. 

Link to comment
https://forums.phpfreaks.com/topic/151796-uasort-compare-3-or-more-values/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.