Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何使变量不小于零?像:
$var=(($add-$substract) || 0);
这适用于 JavaScript,但不适用于 PHP。有人能帮我吗?
谢谢!
至于你关心整数,我觉得max很方便:
max
$var = max(0, $add-$substract);
您可以使用三元运算符
$var = ($add-$subtract)>0?($add-$subtract):0;