How to cap a PHP int value
You could use min
:
min($sum, 100)
This returns either $sum
if $sum < 100
or 100
otherwise.
You can just use the min
function:
$result = min($result, 100);
You'd have to check them I guess.
$x = 80;
$y = 50;
$z = $x + $y;
$int = ($z > 100) ? 100 : $z;