Käynnissä

PHP Comparison Function

I have a stats comparison sort function for stats using PHP's uasort. This works well with 2 teams however if more than 2 teams are tied, I need to be able to run a number of tie breaking rules. The function right now is:

function Compare_standings($ar1, $ar2){

if ($ar1['pts']<$ar2['pts']) {

return 1;

} elseif ($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['gf'] - $ar1['ga']) < ($ar2['gf'] - $ar2['ga'])) {

return 1;

} elseif (($ar1['gf'] - $ar1['ga']) > ($ar2['gf'] - $ar2['ga'])) {

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;

}

uasort($tstats['tm'], 'Compare_standings');

What I need to happen is add the ability to compare additional variables if 3 or more are tied. So say a team has the same amount of points as 2 other teams, it needs to go through a number of rules based on the 3 values, not just 2.

Taidot: PHP

Näytä lisää: php comparison function, php uasort, number function, function number, sort function, function number comparison php, number comparison functions php, tied, tie, php w, gf, function, additional php, breaking, php elseif, need comparison, additional function, php return, php add points, need additional team, points php, php sort, add function, need php team, php stats

About the Employer:
( 5 reviews ) Ajax, Canada

Projektin tunnus: #412572

Myönnetty käyttäjälle:

kraynyukov

Please check PMB. Thanks.

50 $ USD 0 päivässä
(12 arvostelua)
5.0

13 freelanceria on tarjonnut keskimäärin 68 $ tähän työhön

lightcresent

Get it solved... Thanks

75 $ USD 0 päivässä
(481 arvostelua)
9.0
soner

I can do this easily. Please contact if interested.

45 $ USD 0 päivässä
(121 arvostelua)
8.1
naumanrandhawa

Its so simple to do. I am expert in php,c++ aand may more. its a simple loogic to be implemented. i can do it for you in a very reasonble amount thanx. check pmb

35 $ USD 0 päivässä
(153 arvostelua)
7.4
momleetech

We can do it

50 $ USD 1 päivässä
(104 arvostelua)
6.7
karmu

hi i am an expert developer from japan . with work experience of 9 year in PHP/Mysql. i am interested for the project. lets do it. Thanks

50 $ USD 0 päivässä
(62 arvostelua)
6.0
hieutc

Hi, Please check your PM. Regards,

100 $ USD 0 päivässä
(23 arvostelua)
5.8
murza

Please read PM for details.

200 $ USD 1 päivässä
(11 arvostelua)
5.0
sublimecode

This sounds like fun. I have 4+ years experience in PHP development.

50 $ USD 1 päivässä
(8 arvostelua)
4.0
travo

Hi, I am interested and can easily make this function happen. Please see the PMB. Thanks

35 $ USD 0 päivässä
(3 arvostelua)
2.4
MichaelHuang

hi,i am a professional PHP developer,i can help you to improve this function.

45 $ USD 1 päivässä
(1 arvostelu)
0.0
ayandisharingan

i can handle that if you are interest write me to ayandi_lemus from yahoo dot com

50 $ USD 1 päivässä
(0 arvostelua)
0.0
sivakotamraj

I can do it for you.please accept my bid

100 $ USD 4 päivässä
(0 arvostelua)
0.0