Jump to content

Sort - Compare More Than 2 Values


fanfavorite

Recommended Posts

I'll make it simple.  If I get the process, I can figure out how to incorporate mine better.  Here is the simple version right now:

 

	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;
	}
   		return 0;
}

 

What I would like to do is if there are more than 2 with the same amount of "pts" then check all 3: 

 

	function Compare_standings($ar1, $ar2, $ar3){ 
	if ($ar1['pts']<$ar2['pts']) {
      			return 1;
	} else if ($ar1['pts']>$ar2['pts']) {
      			return -1;
	}
	if ($ar3['pts'] == $ar1['pts']) {
		if (in_array($ar1['id'],$ar2['teamsbeat']) AND in_array($ar3['id'],$ar2['teamsbeat'])) {
			return 1;
		} elseif (in_array($ar2['id'],$ar1['teamsbeat']) AND in_array($ar3['id'],$ar1['teamsbeat'])) {
			return -1;
		}
	} else {
		if (in_array($ar1['id'],$ar2['teamsbeat'])) {
			return 1;
		} elseif (in_array($ar2['id'],$ar1['teamsbeat'])) {
			return -1;
		}
	}
   		return 0;
}

 

Not sure exactly how I should be structuring because not sure how the compare works with more than 2 values, but this should show what I am trying to do.

 

Thanks!

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.