Search code examples
phpzero

Not less than zero - make a variable which is less than zero to zero


How can I make a variable that will not be less than zero? Like:

$var=(($add-$substract) || 0);

That works in JavaScript, but not in PHP. Can someone help me?

Thanks!


Solution

  • You could use ternary operators

    $var = ($add-$subtract)>0?($add-$subtract):0;