将负数变为0的默认php函数

2022-01-17 00:00:00 math numbers variables php

有这种事吗?

例如

$var = -5;
echo thefunction($var); // should be 0


$var = 5;
echo thefunction($var); // should be 5

推荐答案

试试max($var,0),会有想要的效果.有关详细信息,请参阅手册页.

Try max($var,0), which will have the desired effect. See the manual page for more information.

相关文章