Default php function that turns negative numbers in 0

前端 未结 5 676
谎友^
谎友^ 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条回答
  •  旧时难觅i
    2020-12-29 01:28

    function thefunction($number){
      if ($number < 0)
        return 0;
      return $number; 
    }
    

    that should do the trick

提交回复
热议问题