Nate
Nate

Reputation: 28364

Is there a function for limiting values?

If I'm subtracting two variables and don't want the result to be less than zero, I can do this:

$diff = ($a-$b)>=0?($a-$b):0;

Is there a function for this sort thing? That is, defining a maximum or minimum for the result of an operation?

It seems like there would be something like this:

$diff = min($a-$b, 0);

But when I tried searching all that came up was stuff related to memory limits.

Upvotes: 0

Views: 48

Answers (1)

serakfalcon
serakfalcon

Reputation: 3531

$diff = max($a-$b,0)

remember, if $a-$b is negative, it will be < 0

Upvotes: 1

Related Questions