Much like this site, my current project has reputation and in the script that I\'m working on I need to calculate the ratio between two users\' reputations.
I don’t recommend to change any user’s reputation artificially solely to make the math work. Instead you can do this:
function calc_rep_ratio($self, other)
{
if ($self->rep != 0) {
return $other->rep / $self->rep;
} else {
return NAN;
}
}
Then use the function
$defender->ratio = calc_rep_ratio($defender, $attacker);
$attacker->ratio = calc_rep_ratio($attacker, $defender);
In the presentation, you can check for the number
if (is_nan($user->ratio)) {
echo 'No ratio available';
} else {
echo $user->ratio;
}