I have four variables $a
, $b
, $c
and $d
. They each have an integer value assigned to them. I need to find the variable with the highest value (Not the value itself). This is what I tried :
// $a, $b, $c, $d are initialized with values here
$highest_value = max($a,$b,$c,$d);
if($a==$highest_value){$biggest_variable = 'a'};
if($b==$highest_value){$biggest_variable = 'b'};
if($c==$highest_value){$biggest_variable = 'c'};
if($d==$highest_value){$biggest_variable = 'd'};
While not very efficient, it gets the job done. But this falls flat if any of the variables are equal in value. This seemingly simple problem has me stumped! Is there any simpler solution than manually comparing each variable to check if any are equal?
EDIT : Okay so, the reason for sorting is for scoring. Each variable constitutes a Team. Scores are calculated as :
Winning Team = 1,000,000 / Value , Other Teams = 200,000 / Value
So with a
= 10 and rest having values 3,4,5
for b,c,d
, Score for a is 1,000,000 / 10
, Rest would be 200,000
divided by their respective values.