Page 1 of 1

Comparing 3 Numeric Values

Posted: Tue Jul 01, 2008 12:01 am
by annnthony
Is there any way to use PHP to compare 3 numbers and check that they are within a certain range? I'm sure I could do some very lengthy if statements to compare, but if there's a way to just use an array or something else clever, advice would be great.

For example, if I'd want the numbers to all be within 10 of each other, and I had the numbers 39, 41, and 44... I'm not sure how to explain without using code, but hopefully the first little paragraph will be helpful enough to explain stuff.

Re: Comparing 3 Numeric Values

Posted: Tue Jul 01, 2008 12:48 am
by Ollie Saunders

Code: Select all

// assume $nums is an array
if (max($nums) - min($nums) > RANGE_LIMIT) {
   echo 'Whoa there little man peach';
} else {
   echo 'Having good times, almost as good as that soup.';
}