I am working on a class to manipulate html hex color codes in php. Internally, the class treats RGB values as decimal numbers. When I add or subtract, I never want the value to exceed 255, but not "start" from scratch.
Unless, of course, I can do something piecemeal
if ( $val > 255 ) {
$val = 255;
}
if ( $val < 0 ) {
$val = 0;
}
But this one is detailed: P
Is there a smart, single-line way, can I make the value stay from 0 to 255?
source
share