Default php function that turns negative numbers in 0

前端 未结 5 667
谎友^
谎友^ 2020-12-29 01:01

Is there such a thing?

for eg

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


$var = 5;
echo thefunction($var); // should be 5
5条回答
  •  温柔的废话
    2020-12-29 01:25

    Not built-in but, here you have:

    function thefunction($var){
       return ($var < 0 ? 0 : $var);
    }
    

    Hope this helps

提交回复
热议问题