is there a php function to return the difference between any 2 integer numbers as a positive integer?
As pointed out by @Phylogenesis, you can use the abs()
function. For example:
$var1 = -2;
$var2 = -30;
echo abs($var1 - $var2); // 28
You could also define your own function:
function abs_diff($v1, $v2) {
$diff = $v1 - $v2;
return $diff < 0 ? (-1) * $diff : $diff;
}
echo abs_diff(-2, -30); // 28
Use the absolute value function of php of the difference of the two numbers.
$answer = abs($num1 - $num2);