Calculate Margin in PHP -
i hope can me on this. want have margin between 2 numbers no matter if positive or negative. in case, below want result $aor $b 2. of course, can use if else, sure there better , more elegant way in php?
it sounds google show me correct way within seconds, have not found useful.
please help. much!
$a = 1 - 3; $b = 3 - 1; if $a<0{ $result = $a*-1; }else{ $result = $a;}
you can use absolute value method: abs()
$result = abs($a); // $result 2
Comments
Post a Comment