php中的unsigned tinyint? [英] unsigned tinyint in php?
本文介绍了php中的unsigned tinyint?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在研究一个类来操作php中的html十六进制颜色代码。在内部,该类将RGB值视为小数。当我加或减时,我从不希望该值超过255,也不希望'subceed'为零。
I'm working on a class to manipulate html hex color codes in php. Internally, the class treats RGB values as decimals. When I'm adding or subtracting, I never want the value to exceed 255 nor 'subceed' zero.
如果当然,我可以做点零碎的事情,如
If course, I can do something piecemeal like
if ( $val > 255 ) {
$val = 255;
}
if ( $val < 0 ) {
$val = 0;
}
但这很详细:P
我是否有一种聪明的,有利可图的方法可以使值保持在0到255之间?
推荐答案
你可能会说:
$ val = max(0,min(255,$ val));
You could possibly say something like: $val = max(0, min(255, $val));
这篇关于php中的unsigned tinyint?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文