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.
Comparing 3 Numeric Values
Moderator: General Moderators
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
Re: Comparing 3 Numeric Values
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.';
}